43#ifndef OPENCV_CUDA_FILTERS_HPP
44#define OPENCV_CUDA_FILTERS_HPP
57namespace cv {
namespace cuda {
namespace device
59 template <
typename Ptr2D>
struct PointFilter
61 typedef typename Ptr2D::elem_type elem_type;
62 typedef float index_type;
64 explicit __host__ __device__ __forceinline__ PointFilter(
const Ptr2D& src_,
float fx = 0.f,
float fy = 0.f)
71 __device__ __forceinline__ elem_type operator ()(
float y,
float x)
const
73 return src(__float2int_rz(y), __float2int_rz(x));
79 template <
typename Ptr2D>
struct LinearFilter
81 typedef typename Ptr2D::elem_type elem_type;
82 typedef float index_type;
84 explicit __host__ __device__ __forceinline__ LinearFilter(
const Ptr2D& src_,
float fx = 0.f,
float fy = 0.f)
90 __device__ __forceinline__ elem_type operator ()(
float y,
float x)
const
92 typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type;
94 work_type out = VecTraits<work_type>::all(0);
96 const int x1 = __float2int_rd(x);
97 const int y1 = __float2int_rd(y);
98 const int x2 = x1 + 1;
99 const int y2 = y1 + 1;
101 elem_type src_reg = src(y1, x1);
102 out = out + src_reg * ((x2 - x) * (y2 - y));
104 src_reg = src(y1, x2);
105 out = out + src_reg * ((x - x1) * (y2 - y));
107 src_reg = src(y2, x1);
108 out = out + src_reg * ((x2 - x) * (y - y1));
110 src_reg = src(y2, x2);
111 out = out + src_reg * ((x - x1) * (y - y1));
113 return saturate_cast<elem_type>(out);
119 template <
typename Ptr2D>
struct CubicFilter
121 typedef typename Ptr2D::elem_type elem_type;
122 typedef float index_type;
123 typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type;
125 explicit __host__ __device__ __forceinline__ CubicFilter(
const Ptr2D& src_,
float fx = 0.f,
float fy = 0.f)
132 static __device__ __forceinline__
float bicubicCoeff(
float x_)
137 return x * x * (1.5f * x - 2.5f) + 1.0f;
141 return x * (x * (-0.5f * x + 2.5f) - 4.0f) + 2.0f;
149 __device__ elem_type operator ()(
float y,
float x)
const
151 const float xmin = ::ceilf(x - 2.0f);
152 const float xmax = ::floorf(x + 2.0f);
154 const float ymin = ::ceilf(y - 2.0f);
155 const float ymax = ::floorf(y + 2.0f);
157 work_type sum = VecTraits<work_type>::all(0);
160 for (
float cy = ymin; cy <= ymax; cy += 1.0f)
162 for (
float cx = xmin; cx <= xmax; cx += 1.0f)
164 const float w = bicubicCoeff(x - cx) * bicubicCoeff(y - cy);
165 sum = sum + w * src(__float2int_rd(cy), __float2int_rd(cx));
170 work_type res = (!wsum)? VecTraits<work_type>::all(0) : sum / wsum;
172 return saturate_cast<elem_type>(res);
178 template <
typename Ptr2D>
struct IntegerAreaFilter
180 typedef typename Ptr2D::elem_type elem_type;
181 typedef float index_type;
183 explicit __host__ __device__ __forceinline__ IntegerAreaFilter(
const Ptr2D& src_,
float scale_x_,
float scale_y_)
184 : src(src_), scale_x(scale_x_), scale_y(scale_y_), scale(1.f / (scale_x * scale_y)) {}
186 __device__ __forceinline__ elem_type operator ()(
float y,
float x)
const
188 float fsx1 = x * scale_x;
189 float fsx2 = fsx1 + scale_x;
191 int sx1 = __float2int_ru(fsx1);
192 int sx2 = __float2int_rd(fsx2);
194 float fsy1 = y * scale_y;
195 float fsy2 = fsy1 + scale_y;
197 int sy1 = __float2int_ru(fsy1);
198 int sy2 = __float2int_rd(fsy2);
200 typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type;
201 work_type out = VecTraits<work_type>::all(0.f);
203 for(
int dy = sy1; dy < sy2; ++dy)
204 for(
int dx = sx1; dx < sx2; ++dx)
206 out = out + src(dy, dx) * scale;
209 return saturate_cast<elem_type>(out);
213 float scale_x, scale_y ,scale;
216 template <
typename Ptr2D>
struct AreaFilter
218 typedef typename Ptr2D::elem_type elem_type;
219 typedef float index_type;
221 explicit __host__ __device__ __forceinline__ AreaFilter(
const Ptr2D& src_,
float scale_x_,
float scale_y_)
222 : src(src_), scale_x(scale_x_), scale_y(scale_y_){}
224 __device__ __forceinline__ elem_type operator ()(
float y,
float x)
const
226 float fsx1 = x * scale_x;
227 float fsx2 = fsx1 + scale_x;
229 int sx1 = __float2int_ru(fsx1);
230 int sx2 = __float2int_rd(fsx2);
232 float fsy1 = y * scale_y;
233 float fsy2 = fsy1 + scale_y;
235 int sy1 = __float2int_ru(fsy1);
236 int sy2 = __float2int_rd(fsy2);
238 float scale = 1.f / (fminf(scale_x, src.width - fsx1) * fminf(scale_y, src.height - fsy1));
240 typedef typename TypeVec<float, VecTraits<elem_type>::cn>::vec_type work_type;
241 work_type out = VecTraits<work_type>::all(0.f);
243 for (
int dy = sy1; dy < sy2; ++dy)
245 for (
int dx = sx1; dx < sx2; ++dx)
246 out = out + src(dy, dx) * scale;
249 out = out + src(dy, (sx1 -1) ) * ((sx1 - fsx1) * scale);
252 out = out + src(dy, sx2) * ((fsx2 -sx2) * scale);
256 for (
int dx = sx1; dx < sx2; ++dx)
257 out = out + src( (sy1 - 1) , dx) * ((sy1 -fsy1) * scale);
260 for (
int dx = sx1; dx < sx2; ++dx)
261 out = out + src(sy2, dx) * ((fsy2 -sy2) * scale);
263 if ((sy1 > fsy1) && (sx1 > fsx1))
264 out = out + src( (sy1 - 1) , (sx1 - 1)) * ((sy1 -fsy1) * (sx1 -fsx1) * scale);
266 if ((sy1 > fsy1) && (sx2 < fsx2))
267 out = out + src( (sy1 - 1) , sx2) * ((sy1 -fsy1) * (fsx2 -sx2) * scale);
269 if ((sy2 < fsy2) && (sx2 < fsx2))
270 out = out + src(sy2, sx2) * ((fsy2 -sy2) * (fsx2 -sx2) * scale);
272 if ((sy2 < fsy2) && (sx1 > fsx1))
273 out = out + src(sy2, (sx1 - 1)) * ((fsy2 -sy2) * (sx1 -fsx1) * scale);
275 return saturate_cast<elem_type>(out);
279 float scale_x, scale_y;
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75