diff --git a/modules/cudawarping/include/opencv2/cudawarping.hpp b/modules/cudawarping/include/opencv2/cudawarping.hpp index 45cca1ccf86..b9ca957358e 100644 --- a/modules/cudawarping/include/opencv2/cudawarping.hpp +++ b/modules/cudawarping/include/opencv2/cudawarping.hpp @@ -70,6 +70,8 @@ namespace cv { namespace cuda { @param ymap Y values. Only CV_32FC1 type is supported. @param interpolation Interpolation method (see resize ). INTER_NEAREST , INTER_LINEAR and INTER_CUBIC are supported for now. +The extra flag WARP_RELATIVE_MAP can be ORed to the interpolation method +(e.g. INTER_LINEAR | WARP_RELATIVE_MAP) @param borderMode Pixel extrapolation method (see borderInterpolate ). BORDER_REFLECT101 , BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now. @param borderValue Value used in case of a constant border. By default, it is 0. @@ -79,6 +81,10 @@ The function transforms the source image using the specified map: \f[\texttt{dst} (x,y) = \texttt{src} (xmap(x,y), ymap(x,y))\f] +with the WARP_RELATIVE_MAP flag : + +\f[\texttt{dst} (x,y) = \texttt{src} (x+map_x(x,y),y+map_y(x,y))\f] + Values of pixels with non-integer coordinates are computed using the bilinear interpolation. @sa remap diff --git a/modules/cudawarping/src/cuda/remap.cu b/modules/cudawarping/src/cuda/remap.cu index 38edf19ae24..8f698a2ffb4 100644 --- a/modules/cudawarping/src/cuda/remap.cu +++ b/modules/cudawarping/src/cuda/remap.cu @@ -68,9 +68,23 @@ namespace cv { namespace cuda { namespace device } } + template __global__ void remap_relative(const Ptr2D src, const PtrStepf mapx, const PtrStepf mapy, PtrStepSz dst) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < dst.cols && y < dst.rows) + { + const float xcoo = x+mapx.ptr(y)[x]; + const float ycoo = y+mapy.ptr(y)[x]; + + dst.ptr(y)[x] = saturate_cast(src(ycoo, xcoo)); + } + } + template