mirror of https://github.com/opencv/opencv.git
wrote more complicated tests for them implemented own version of warpAffine and warpPerspective for different border interpolation types refactored some gpu testspull/13383/head
parent
6e2507c197
commit
ade7394e77
33 changed files with 6242 additions and 4544 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,380 @@ |
||||
/*M/////////////////////////////////////////////////////////////////////////////////////// |
||||
// |
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
||||
// |
||||
// By downloading, copying, installing or using the software you agree to this license. |
||||
// If you do not agree to this license, do not download, install, |
||||
// copy or use the software. |
||||
// |
||||
// |
||||
// License Agreement |
||||
// For Open Source Computer Vision Library |
||||
// |
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
||||
// Third party copyrights are property of their respective owners. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without modification, |
||||
// are permitted provided that the following conditions are met: |
||||
// |
||||
// * Redistribution's of source code must retain the above copyright notice, |
||||
// this list of conditions and the following disclaimer. |
||||
// |
||||
// * Redistribution's in binary form must reproduce the above copyright notice, |
||||
// this list of conditions and the following disclaimer in the documentation |
||||
// and/or other materials provided with the distribution. |
||||
// |
||||
// * The name of the copyright holders may not be used to endorse or promote products |
||||
// derived from this software without specific prior written permission. |
||||
// |
||||
// This software is provided by the copyright holders and contributors "as is" and |
||||
// any express or implied warranties, including, but not limited to, the implied |
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed. |
||||
// In no event shall the Intel Corporation or contributors be liable for any direct, |
||||
// indirect, incidental, special, exemplary, or consequential damages |
||||
// (including, but not limited to, procurement of substitute goods or services; |
||||
// loss of use, data, or profits; or business interruption) however caused |
||||
// and on any theory of liability, whether in contract, strict liability, |
||||
// or tort (including negligence or otherwise) arising in any way out of |
||||
// the use of this software, even if advised of the possibility of such damage. |
||||
// |
||||
//M*/ |
||||
|
||||
#include "internal_shared.hpp" |
||||
#include "opencv2/gpu/device/border_interpolate.hpp" |
||||
#include "opencv2/gpu/device/vec_traits.hpp" |
||||
#include "opencv2/gpu/device/vec_math.hpp" |
||||
#include "opencv2/gpu/device/saturate_cast.hpp" |
||||
#include "opencv2/gpu/device/filters.hpp" |
||||
|
||||
namespace cv { namespace gpu { namespace device |
||||
{ |
||||
namespace imgproc |
||||
{ |
||||
__constant__ float c_warpMat[3 * 3]; |
||||
|
||||
struct AffineTransform |
||||
{ |
||||
static __device__ __forceinline__ float2 calcCoord(int x, int y) |
||||
{ |
||||
const float xcoo = c_warpMat[0] * x + c_warpMat[1] * y + c_warpMat[2]; |
||||
const float ycoo = c_warpMat[3] * x + c_warpMat[4] * y + c_warpMat[5]; |
||||
|
||||
return make_float2(xcoo, ycoo); |
||||
} |
||||
}; |
||||
|
||||
struct PerspectiveTransform |
||||
{ |
||||
static __device__ __forceinline__ float2 calcCoord(int x, int y) |
||||
{ |
||||
const float coeff = 1.0f / (c_warpMat[6] * x + c_warpMat[7] * y + c_warpMat[8]); |
||||
|
||||
const float xcoo = coeff * (c_warpMat[0] * x + c_warpMat[1] * y + c_warpMat[2]); |
||||
const float ycoo = coeff * (c_warpMat[3] * x + c_warpMat[4] * y + c_warpMat[5]); |
||||
|
||||
return make_float2(xcoo, ycoo); |
||||
} |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////// |
||||
// Build Maps |
||||
|
||||
template <class Transform> __global__ void buildWarpMaps(DevMem2Df xmap, PtrStepf ymap) |
||||
{ |
||||
const int x = blockDim.x * blockIdx.x + threadIdx.x; |
||||
const int y = blockDim.y * blockIdx.y + threadIdx.y; |
||||
|
||||
if (x < xmap.cols && y < xmap.rows) |
||||
{ |
||||
const float2 coord = Transform::calcCoord(x, y); |
||||
|
||||
xmap(y, x) = coord.x; |
||||
ymap(y, x) = coord.y; |
||||
} |
||||
} |
||||
|
||||
template <class Transform> void buildWarpMaps_caller(DevMem2Df xmap, DevMem2Df ymap, cudaStream_t stream) |
||||
{ |
||||
dim3 block(32, 8); |
||||
dim3 grid(divUp(xmap.cols, block.x), divUp(xmap.rows, block.y)); |
||||
|
||||
buildWarpMaps<Transform><<<grid, block, 0, stream>>>(xmap, ymap); |
||||
cudaSafeCall( cudaGetLastError() ); |
||||
|
||||
if (stream == 0) |
||||
cudaSafeCall( cudaDeviceSynchronize() ); |
||||
} |
||||
|
||||
void buildWarpAffineMaps_gpu(float coeffs[2 * 3], DevMem2Df xmap, DevMem2Df ymap, cudaStream_t stream) |
||||
{ |
||||
cudaSafeCall( cudaMemcpyToSymbol(c_warpMat, coeffs, 2 * 3 * sizeof(float)) ); |
||||
|
||||
buildWarpMaps_caller<AffineTransform>(xmap, ymap, stream); |
||||
} |
||||
|
||||
void buildWarpPerspectiveMaps_gpu(float coeffs[3 * 3], DevMem2Df xmap, DevMem2Df ymap, cudaStream_t stream) |
||||
{ |
||||
cudaSafeCall( cudaMemcpyToSymbol(c_warpMat, coeffs, 3 * 3 * sizeof(float)) ); |
||||
|
||||
buildWarpMaps_caller<PerspectiveTransform>(xmap, ymap, stream); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////// |
||||
// Warp |
||||
|
||||
template <class Transform, class Ptr2D, typename T> __global__ void warp(const Ptr2D src, DevMem2D_<T> 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 float2 coord = Transform::calcCoord(x, y); |
||||
|
||||
dst.ptr(y)[x] = saturate_cast<T>(src(coord.y, coord.x)); |
||||
} |
||||
} |
||||
|
||||
template <class Transform, template <typename> class Filter, template <typename> class B, typename T> struct WarpDispatcherStream |
||||
{ |
||||
static void call(DevMem2D_<T> src, DevMem2D_<T> dst, const float* borderValue, cudaStream_t stream, int) |
||||
{ |
||||
typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type work_type; |
||||
|
||||
dim3 block(32, 8); |
||||
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); |
||||
|
||||
B<work_type> brd(src.rows, src.cols, VecTraits<work_type>::make(borderValue)); |
||||
BorderReader< PtrStep<T>, B<work_type> > brdSrc(src, brd); |
||||
Filter< BorderReader< PtrStep<T>, B<work_type> > > filter_src(brdSrc); |
||||
|
||||
warp<Transform><<<grid, block, 0, stream>>>(filter_src, dst); |
||||
cudaSafeCall( cudaGetLastError() ); |
||||
} |
||||
}; |
||||
|
||||
template <class Transform, template <typename> class Filter, template <typename> class B, typename T> struct WarpDispatcherNonStream |
||||
{ |
||||
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, DevMem2D_<T> dst, const float* borderValue, int) |
||||
{ |
||||
typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type work_type; |
||||
|
||||
dim3 block(32, 8); |
||||
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); |
||||
|
||||
B<work_type> brd(src.rows, src.cols, VecTraits<work_type>::make(borderValue)); |
||||
BorderReader< PtrStep<T>, B<work_type> > brdSrc(src, brd); |
||||
Filter< BorderReader< PtrStep<T>, B<work_type> > > filter_src(brdSrc); |
||||
|
||||
warp<Transform><<<grid, block>>>(filter_src, dst); |
||||
cudaSafeCall( cudaGetLastError() ); |
||||
|
||||
cudaSafeCall( cudaDeviceSynchronize() ); |
||||
} |
||||
}; |
||||
|
||||
#define OPENCV_GPU_IMPLEMENT_WARP_TEX(type) \ |
||||
texture< type , cudaTextureType2D > tex_warp_ ## type (0, cudaFilterModePoint, cudaAddressModeClamp); \ |
||||
struct tex_warp_ ## type ## _reader \ |
||||
{ \ |
||||
typedef type elem_type; \ |
||||
typedef int index_type; \ |
||||
int xoff, yoff; \ |
||||
tex_warp_ ## type ## _reader (int xoff_, int yoff_) : xoff(xoff_), yoff(yoff_) {} \ |
||||
__device__ __forceinline__ elem_type operator ()(index_type y, index_type x) const \ |
||||
{ \ |
||||
return tex2D(tex_warp_ ## type , x + xoff, y + yoff); \ |
||||
} \ |
||||
}; \ |
||||
template <class Transform, template <typename> class Filter, template <typename> class B> struct WarpDispatcherNonStream<Transform, Filter, B, type> \ |
||||
{ \ |
||||
static void call(DevMem2D_< type > src, DevMem2D_< type > srcWhole, int xoff, int yoff, DevMem2D_< type > dst, const float* borderValue, int cc) \ |
||||
{ \ |
||||
typedef typename TypeVec<float, VecTraits< type >::cn>::vec_type work_type; \ |
||||
dim3 block(32, cc >= 20 ? 8 : 4); \ |
||||
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); \ |
||||
bindTexture(&tex_warp_ ## type , srcWhole); \ |
||||
tex_warp_ ## type ##_reader texSrc(xoff, yoff); \ |
||||
B<work_type> brd(src.rows, src.cols, VecTraits<work_type>::make(borderValue)); \ |
||||
BorderReader< tex_warp_ ## type ##_reader, B<work_type> > brdSrc(texSrc, brd); \ |
||||
Filter< BorderReader< tex_warp_ ## type ##_reader, B<work_type> > > filter_src(brdSrc); \ |
||||
warp<Transform><<<grid, block>>>(filter_src, dst); \ |
||||
cudaSafeCall( cudaGetLastError() ); \ |
||||
cudaSafeCall( cudaDeviceSynchronize() ); \ |
||||
} \ |
||||
}; \ |
||||
template <class Transform, template <typename> class Filter> struct WarpDispatcherNonStream<Transform, Filter, BrdReplicate, type> \ |
||||
{ \ |
||||
static void call(DevMem2D_< type > src, DevMem2D_< type > srcWhole, int xoff, int yoff, DevMem2D_< type > dst, const float*, int) \ |
||||
{ \ |
||||
dim3 block(32, 8); \ |
||||
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); \ |
||||
bindTexture(&tex_warp_ ## type , srcWhole); \ |
||||
tex_warp_ ## type ##_reader texSrc(xoff, yoff); \ |
||||
if (srcWhole.cols == src.cols && srcWhole.rows == src.rows) \ |
||||
{ \ |
||||
Filter< tex_warp_ ## type ##_reader > filter_src(texSrc); \ |
||||
warp<Transform><<<grid, block>>>(filter_src, dst); \ |
||||
} \ |
||||
else \ |
||||
{ \ |
||||
BrdReplicate<type> brd(src.rows, src.cols); \ |
||||
BorderReader< tex_warp_ ## type ##_reader, BrdReplicate<type> > brdSrc(texSrc, brd); \ |
||||
Filter< BorderReader< tex_warp_ ## type ##_reader, BrdReplicate<type> > > filter_src(brdSrc); \ |
||||
warp<Transform><<<grid, block>>>(filter_src, dst); \ |
||||
} \ |
||||
cudaSafeCall( cudaGetLastError() ); \ |
||||
cudaSafeCall( cudaDeviceSynchronize() ); \ |
||||
} \ |
||||
}; |
||||
|
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(uchar) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(uchar2) |
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(uchar4) |
||||
|
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(schar) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(char2) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(char4) |
||||
|
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(ushort) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(ushort2) |
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(ushort4) |
||||
|
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(short) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(short2) |
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(short4) |
||||
|
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(int) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(int2) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(int4) |
||||
|
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(float) |
||||
//OPENCV_GPU_IMPLEMENT_WARP_TEX(float2) |
||||
OPENCV_GPU_IMPLEMENT_WARP_TEX(float4) |
||||
|
||||
#undef OPENCV_GPU_IMPLEMENT_WARP_TEX |
||||
|
||||
template <class Transform, template <typename> class Filter, template <typename> class B, typename T> struct WarpDispatcher |
||||
{ |
||||
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, DevMem2D_<T> dst, const float* borderValue, cudaStream_t stream, int cc) |
||||
{ |
||||
if (stream == 0) |
||||
WarpDispatcherNonStream<Transform, Filter, B, T>::call(src, srcWhole, xoff, yoff, dst, borderValue, cc); |
||||
else |
||||
WarpDispatcherStream<Transform, Filter, B, T>::call(src, dst, borderValue, stream, cc); |
||||
} |
||||
}; |
||||
|
||||
template <class Transform, typename T> |
||||
void warp_caller(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc) |
||||
{ |
||||
typedef void (*func_t)(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, DevMem2D_<T> dst, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
static const func_t funcs[3][5] = |
||||
{ |
||||
{ |
||||
WarpDispatcher<Transform, PointFilter, BrdReflect101, T>::call, |
||||
WarpDispatcher<Transform, PointFilter, BrdReplicate, T>::call, |
||||
WarpDispatcher<Transform, PointFilter, BrdConstant, T>::call, |
||||
WarpDispatcher<Transform, PointFilter, BrdReflect, T>::call, |
||||
WarpDispatcher<Transform, PointFilter, BrdWrap, T>::call |
||||
}, |
||||
{ |
||||
WarpDispatcher<Transform, LinearFilter, BrdReflect101, T>::call, |
||||
WarpDispatcher<Transform, LinearFilter, BrdReplicate, T>::call, |
||||
WarpDispatcher<Transform, LinearFilter, BrdConstant, T>::call, |
||||
WarpDispatcher<Transform, LinearFilter, BrdReflect, T>::call, |
||||
WarpDispatcher<Transform, LinearFilter, BrdWrap, T>::call |
||||
}, |
||||
{ |
||||
WarpDispatcher<Transform, CubicFilter, BrdReflect101, T>::call, |
||||
WarpDispatcher<Transform, CubicFilter, BrdReplicate, T>::call, |
||||
WarpDispatcher<Transform, CubicFilter, BrdConstant, T>::call, |
||||
WarpDispatcher<Transform, CubicFilter, BrdReflect, T>::call, |
||||
WarpDispatcher<Transform, CubicFilter, BrdWrap, T>::call |
||||
} |
||||
}; |
||||
|
||||
funcs[interpolation][borderMode](static_cast< DevMem2D_<T> >(src), static_cast< DevMem2D_<T> >(srcWhole), xoff, yoff, |
||||
static_cast< DevMem2D_<T> >(dst), borderValue, stream, cc); |
||||
} |
||||
|
||||
template <typename T> void warpAffine_gpu(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc) |
||||
{ |
||||
cudaSafeCall( cudaMemcpyToSymbol(c_warpMat, coeffs, 2 * 3 * sizeof(float)) ); |
||||
|
||||
warp_caller<AffineTransform, T>(src, srcWhole, xoff, yoff, dst, interpolation, borderMode, borderValue, stream, cc); |
||||
} |
||||
|
||||
template void warpAffine_gpu<uchar >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<uchar2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<uchar3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<uchar4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
//template void warpAffine_gpu<schar>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<char2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<char3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<char4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template void warpAffine_gpu<ushort >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<ushort2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<ushort3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<ushort4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template void warpAffine_gpu<short >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<short2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<short3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<short4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
//template void warpAffine_gpu<int >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<int2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<int3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<int4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template void warpAffine_gpu<float >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpAffine_gpu<float2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<float3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpAffine_gpu<float4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template <typename T> void warpPerspective_gpu(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc) |
||||
{ |
||||
cudaSafeCall( cudaMemcpyToSymbol(c_warpMat, coeffs, 3 * 3 * sizeof(float)) ); |
||||
|
||||
warp_caller<PerspectiveTransform, T>(src, srcWhole, xoff, yoff, dst, interpolation, borderMode, borderValue, stream, cc); |
||||
} |
||||
|
||||
template void warpPerspective_gpu<uchar >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<uchar2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<uchar3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<uchar4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
//template void warpPerspective_gpu<schar>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<char2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<char3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<char4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template void warpPerspective_gpu<ushort >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<ushort2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<ushort3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<ushort4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template void warpPerspective_gpu<short >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<short2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<short3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<short4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
//template void warpPerspective_gpu<int >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<int2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<int3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<int4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
template void warpPerspective_gpu<float >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
//template void warpPerspective_gpu<float2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<float3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
template void warpPerspective_gpu<float4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
} // namespace imgproc |
||||
}}} // namespace cv { namespace gpu { namespace device |
@ -0,0 +1,105 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifndef HAVE_CUDA |
||||
|
||||
void cv::gpu::remap(const GpuMat&, GpuMat&, const GpuMat&, const GpuMat&, int, int, Scalar, Stream&){ throw_nogpu(); } |
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
namespace cv { namespace gpu { namespace device
|
||||
{ |
||||
namespace imgproc
|
||||
{ |
||||
template <typename T>
|
||||
void remap_gpu(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, DevMem2Df xmap, DevMem2Df ymap, DevMem2Db dst,
|
||||
int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
} |
||||
}}} |
||||
|
||||
void cv::gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, int interpolation, int borderMode, Scalar borderValue, Stream& stream) |
||||
{ |
||||
using namespace cv::gpu::device::imgproc; |
||||
|
||||
typedef void (*func_t)(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, DevMem2Df xmap, DevMem2Df ymap, DevMem2Db dst, int interpolation,
|
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
static const func_t funcs[6][4] =
|
||||
{ |
||||
{remap_gpu<uchar> , 0 /*remap_gpu<uchar2>*/ , remap_gpu<uchar3> , remap_gpu<uchar4> }, |
||||
{0 /*remap_gpu<schar>*/, 0 /*remap_gpu<char2>*/ , 0 /*remap_gpu<char3>*/, 0 /*remap_gpu<char4>*/}, |
||||
{remap_gpu<ushort> , 0 /*remap_gpu<ushort2>*/, remap_gpu<ushort3> , remap_gpu<ushort4> }, |
||||
{remap_gpu<short> , 0 /*remap_gpu<short2>*/ , remap_gpu<short3> , remap_gpu<short4> }, |
||||
{0 /*remap_gpu<int>*/ , 0 /*remap_gpu<int2>*/ , 0 /*remap_gpu<int3>*/ , 0 /*remap_gpu<int4>*/ }, |
||||
{remap_gpu<float> , 0 /*remap_gpu<float2>*/ , remap_gpu<float3> , remap_gpu<float4> } |
||||
}; |
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); |
||||
CV_Assert(xmap.type() == CV_32F && ymap.type() == CV_32F && xmap.size() == ymap.size()); |
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC); |
||||
CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP); |
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1]; |
||||
CV_Assert(func != 0); |
||||
|
||||
int gpuBorderType; |
||||
CV_Assert(tryConvertToGpuBorderType(borderMode, gpuBorderType)); |
||||
|
||||
dst.create(xmap.size(), src.type()); |
||||
|
||||
Scalar_<float> borderValueFloat; |
||||
borderValueFloat = borderValue; |
||||
|
||||
DeviceInfo info; |
||||
int cc = info.majorVersion() * 10 + info.minorVersion(); |
||||
|
||||
Size wholeSize; |
||||
Point ofs; |
||||
src.locateROI(wholeSize, ofs); |
||||
|
||||
func(src, DevMem2Db(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, xmap, ymap,
|
||||
dst, interpolation, gpuBorderType, borderValueFloat.val, StreamAccessor::getStream(stream), cc); |
||||
} |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,150 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifndef HAVE_CUDA |
||||
|
||||
void cv::gpu::resize(const GpuMat&, GpuMat&, Size, double, double, int, Stream&) { throw_nogpu(); } |
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
namespace cv { namespace gpu { namespace device |
||||
{ |
||||
namespace imgproc |
||||
{ |
||||
template <typename T> |
||||
void resize_gpu(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, |
||||
DevMem2Db dst, int interpolation, cudaStream_t stream); |
||||
} |
||||
}}} |
||||
|
||||
void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, double fy, int interpolation, Stream& s) |
||||
{ |
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); |
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC); |
||||
CV_Assert(!(dsize == Size()) || (fx > 0 && fy > 0)); |
||||
|
||||
if (dsize == Size()) |
||||
dsize = Size(saturate_cast<int>(src.cols * fx), saturate_cast<int>(src.rows * fy)); |
||||
else |
||||
{ |
||||
fx = static_cast<double>(dsize.width) / src.cols; |
||||
fy = static_cast<double>(dsize.height) / src.rows; |
||||
} |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
if (dsize == src.size()) |
||||
{ |
||||
if (s) |
||||
s.enqueueCopy(src, dst); |
||||
else |
||||
src.copyTo(dst); |
||||
return; |
||||
} |
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(s); |
||||
|
||||
Size wholeSize; |
||||
Point ofs; |
||||
src.locateROI(wholeSize, ofs); |
||||
|
||||
bool useNpp = (src.type() == CV_8UC1 || src.type() == CV_8UC4); |
||||
useNpp = useNpp && (interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || src.type() == CV_8UC4); |
||||
|
||||
if (useNpp) |
||||
{ |
||||
typedef NppStatus (*func_t)(const Npp8u * pSrc, NppiSize oSrcSize, int nSrcStep, NppiRect oSrcROI, Npp8u * pDst, int nDstStep, NppiSize dstROISize, |
||||
double xFactor, double yFactor, int eInterpolation); |
||||
|
||||
const func_t funcs[4] = { nppiResize_8u_C1R, 0, 0, nppiResize_8u_C4R }; |
||||
|
||||
static const int npp_inter[] = {NPPI_INTER_NN, NPPI_INTER_LINEAR, NPPI_INTER_CUBIC, 0, NPPI_INTER_LANCZOS}; |
||||
|
||||
NppiSize srcsz; |
||||
srcsz.width = wholeSize.width; |
||||
srcsz.height = wholeSize.height; |
||||
|
||||
NppiRect srcrect; |
||||
srcrect.x = ofs.x; |
||||
srcrect.y = ofs.y; |
||||
srcrect.width = src.cols; |
||||
srcrect.height = src.rows; |
||||
|
||||
NppiSize dstsz; |
||||
dstsz.width = dst.cols; |
||||
dstsz.height = dst.rows; |
||||
|
||||
NppStreamHandler h(stream); |
||||
|
||||
nppSafeCall( funcs[src.channels() - 1](src.datastart, srcsz, static_cast<int>(src.step), srcrect, |
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), dstsz, fx, fy, npp_inter[interpolation]) ); |
||||
|
||||
if (stream == 0) |
||||
cudaSafeCall( cudaDeviceSynchronize() ); |
||||
} |
||||
else |
||||
{ |
||||
using namespace ::cv::gpu::device::imgproc; |
||||
|
||||
typedef void (*func_t)(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream); |
||||
|
||||
static const func_t funcs[6][4] = |
||||
{ |
||||
{resize_gpu<uchar> , 0 /*resize_gpu<uchar2>*/ , resize_gpu<uchar3> , resize_gpu<uchar4> }, |
||||
{0 /*resize_gpu<schar>*/, 0 /*resize_gpu<char2>*/ , 0 /*resize_gpu<char3>*/, 0 /*resize_gpu<char4>*/}, |
||||
{resize_gpu<ushort> , 0 /*resize_gpu<ushort2>*/, resize_gpu<ushort3> , resize_gpu<ushort4> }, |
||||
{resize_gpu<short> , 0 /*resize_gpu<short2>*/ , resize_gpu<short3> , resize_gpu<short4> }, |
||||
{0 /*resize_gpu<int>*/ , 0 /*resize_gpu<int2>*/ , 0 /*resize_gpu<int3>*/ , 0 /*resize_gpu<int4>*/ }, |
||||
{resize_gpu<float> , 0 /*resize_gpu<float2>*/ , resize_gpu<float3> , resize_gpu<float4> } |
||||
}; |
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1]; |
||||
CV_Assert(func != 0); |
||||
|
||||
func(src, DevMem2Db(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, |
||||
static_cast<float>(1.0 / fx), static_cast<float>(1.0 / fy), dst, interpolation, stream); |
||||
} |
||||
} |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,463 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifndef HAVE_CUDA |
||||
|
||||
void cv::gpu::warpAffine(const GpuMat&, GpuMat&, const Mat&, Size, int, int, Scalar, Stream&) { throw_nogpu(); } |
||||
void cv::gpu::buildWarpAffineMaps(const Mat&, bool, Size, GpuMat&, GpuMat&, Stream&) { throw_nogpu(); } |
||||
|
||||
void cv::gpu::warpPerspective(const GpuMat&, GpuMat&, const Mat&, Size, int, int, Scalar, Stream&) { throw_nogpu(); } |
||||
void cv::gpu::buildWarpPerspectiveMaps(const Mat&, bool, Size, GpuMat&, GpuMat&, Stream&) { throw_nogpu(); } |
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
namespace cv { namespace gpu { namespace device |
||||
{ |
||||
namespace imgproc |
||||
{ |
||||
void buildWarpAffineMaps_gpu(float coeffs[2 * 3], DevMem2Df xmap, DevMem2Df ymap, cudaStream_t stream); |
||||
|
||||
template <typename T> |
||||
void warpAffine_gpu(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
void buildWarpPerspectiveMaps_gpu(float coeffs[3 * 3], DevMem2Df xmap, DevMem2Df ymap, cudaStream_t stream); |
||||
|
||||
template <typename T> |
||||
void warpPerspective_gpu(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[3 * 3], DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
} |
||||
}}} |
||||
|
||||
void cv::gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream) |
||||
{ |
||||
using namespace cv::gpu::device::imgproc; |
||||
|
||||
CV_Assert(M.rows == 2 && M.cols == 3); |
||||
|
||||
xmap.create(dsize, CV_32FC1); |
||||
ymap.create(dsize, CV_32FC1); |
||||
|
||||
float coeffs[2 * 3]; |
||||
Mat coeffsMat(2, 3, CV_32F, (void*)coeffs); |
||||
|
||||
if (inverse) |
||||
M.convertTo(coeffsMat, coeffsMat.type()); |
||||
else |
||||
{ |
||||
cv::Mat iM; |
||||
invertAffineTransform(M, iM); |
||||
iM.convertTo(coeffsMat, coeffsMat.type()); |
||||
} |
||||
|
||||
buildWarpAffineMaps_gpu(coeffs, xmap, ymap, StreamAccessor::getStream(stream)); |
||||
} |
||||
|
||||
void cv::gpu::buildWarpPerspectiveMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream) |
||||
{ |
||||
using namespace cv::gpu::device::imgproc; |
||||
|
||||
CV_Assert(M.rows == 3 && M.cols == 3); |
||||
|
||||
xmap.create(dsize, CV_32FC1); |
||||
ymap.create(dsize, CV_32FC1); |
||||
|
||||
float coeffs[3 * 3]; |
||||
Mat coeffsMat(3, 3, CV_32F, (void*)coeffs); |
||||
|
||||
if (inverse) |
||||
M.convertTo(coeffsMat, coeffsMat.type()); |
||||
else |
||||
{ |
||||
cv::Mat iM; |
||||
invert(M, iM); |
||||
iM.convertTo(coeffsMat, coeffsMat.type()); |
||||
} |
||||
|
||||
buildWarpPerspectiveMaps_gpu(coeffs, xmap, ymap, StreamAccessor::getStream(stream)); |
||||
} |
||||
|
||||
namespace |
||||
{ |
||||
template<int DEPTH> struct NppTypeTraits; |
||||
template<> struct NppTypeTraits<CV_8U> { typedef Npp8u npp_t; }; |
||||
template<> struct NppTypeTraits<CV_8S> { typedef Npp8s npp_t; }; |
||||
template<> struct NppTypeTraits<CV_16U> { typedef Npp16u npp_t; }; |
||||
template<> struct NppTypeTraits<CV_16S> { typedef Npp16s npp_t; typedef Npp16sc npp_complex_type; }; |
||||
template<> struct NppTypeTraits<CV_32S> { typedef Npp32s npp_t; typedef Npp32sc npp_complex_type; }; |
||||
template<> struct NppTypeTraits<CV_32F> { typedef Npp32f npp_t; typedef Npp32fc npp_complex_type; }; |
||||
template<> struct NppTypeTraits<CV_64F> { typedef Npp64f npp_t; typedef Npp64fc npp_complex_type; }; |
||||
|
||||
template <int DEPTH> struct NppWarpFunc |
||||
{ |
||||
typedef typename NppTypeTraits<DEPTH>::npp_t npp_t; |
||||
|
||||
typedef NppStatus (*func_t)(const npp_t* pSrc, NppiSize srcSize, int srcStep, NppiRect srcRoi, npp_t* pDst, |
||||
int dstStep, NppiRect dstRoi, const double coeffs[][3], |
||||
int interpolation); |
||||
}; |
||||
|
||||
template <int DEPTH, typename NppWarpFunc<DEPTH>::func_t func> struct NppWarp |
||||
{ |
||||
typedef typename NppWarpFunc<DEPTH>::npp_t npp_t; |
||||
|
||||
static void call(const cv::gpu::GpuMat& src, cv::Size wholeSize, cv::Point ofs, cv::gpu::GpuMat& dst, |
||||
double coeffs[][3], cv::Size dsize, int interpolation, cudaStream_t stream) |
||||
{ |
||||
static const int npp_inter[] = {NPPI_INTER_NN, NPPI_INTER_LINEAR, NPPI_INTER_CUBIC}; |
||||
|
||||
dst.create(dsize, src.type()); |
||||
dst.setTo(cv::Scalar::all(0)); |
||||
|
||||
NppiSize srcsz; |
||||
srcsz.height = wholeSize.height; |
||||
srcsz.width = wholeSize.width; |
||||
|
||||
NppiRect srcroi; |
||||
srcroi.x = ofs.x; |
||||
srcroi.y = ofs.y; |
||||
srcroi.height = src.rows; |
||||
srcroi.width = src.cols; |
||||
|
||||
NppiRect dstroi; |
||||
dstroi.x = dstroi.y = 0; |
||||
dstroi.height = dst.rows; |
||||
dstroi.width = dst.cols; |
||||
|
||||
cv::gpu::NppStreamHandler h(stream); |
||||
|
||||
nppSafeCall( func((npp_t*)src.datastart, srcsz, static_cast<int>(src.step), srcroi, |
||||
dst.ptr<npp_t>(), static_cast<int>(dst.step), dstroi, coeffs, npp_inter[interpolation]) ); |
||||
|
||||
if (stream == 0) |
||||
cudaSafeCall( cudaDeviceSynchronize() ); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
void cv::gpu::warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& s) |
||||
{ |
||||
CV_Assert(M.rows == 2 && M.cols == 3); |
||||
|
||||
int interpolation = flags & INTER_MAX; |
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); |
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC); |
||||
CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP); |
||||
|
||||
Size wholeSize; |
||||
Point ofs; |
||||
src.locateROI(wholeSize, ofs); |
||||
|
||||
static const bool useNppTab[6][4][3] = |
||||
{ |
||||
{ |
||||
{false, false, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, true, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, true, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, true} |
||||
}, |
||||
{ |
||||
{false, true, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, true} |
||||
} |
||||
}; |
||||
|
||||
bool useNpp = borderMode == BORDER_CONSTANT; |
||||
useNpp = useNpp && useNppTab[src.depth()][src.channels() - 1][interpolation]; |
||||
#ifdef linux |
||||
// NPP bug on float data
|
||||
useNpp = useNpp && src.depth() != CV_32F; |
||||
#endif |
||||
|
||||
if (useNpp) |
||||
{ |
||||
typedef void (*func_t)(const cv::gpu::GpuMat& src, cv::Size wholeSize, cv::Point ofs, cv::gpu::GpuMat& dst, double coeffs[][3], cv::Size dsize, int flags, cudaStream_t stream); |
||||
|
||||
static const func_t funcs[2][6][4] = |
||||
{ |
||||
{ |
||||
{NppWarp<CV_8U, nppiWarpAffine_8u_C1R>::call, 0, NppWarp<CV_8U, nppiWarpAffine_8u_C3R>::call, NppWarp<CV_8U, nppiWarpAffine_8u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_16U, nppiWarpAffine_16u_C1R>::call, 0, NppWarp<CV_16U, nppiWarpAffine_16u_C3R>::call, NppWarp<CV_16U, nppiWarpAffine_16u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_32S, nppiWarpAffine_32s_C1R>::call, 0, NppWarp<CV_32S, nppiWarpAffine_32s_C3R>::call, NppWarp<CV_32S, nppiWarpAffine_32s_C4R>::call}, |
||||
{NppWarp<CV_32F, nppiWarpAffine_32f_C1R>::call, 0, NppWarp<CV_32F, nppiWarpAffine_32f_C3R>::call, NppWarp<CV_32F, nppiWarpAffine_32f_C4R>::call} |
||||
}, |
||||
{ |
||||
{NppWarp<CV_8U, nppiWarpAffineBack_8u_C1R>::call, 0, NppWarp<CV_8U, nppiWarpAffineBack_8u_C3R>::call, NppWarp<CV_8U, nppiWarpAffineBack_8u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_16U, nppiWarpAffineBack_16u_C1R>::call, 0, NppWarp<CV_16U, nppiWarpAffineBack_16u_C3R>::call, NppWarp<CV_16U, nppiWarpAffineBack_16u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_32S, nppiWarpAffineBack_32s_C1R>::call, 0, NppWarp<CV_32S, nppiWarpAffineBack_32s_C3R>::call, NppWarp<CV_32S, nppiWarpAffineBack_32s_C4R>::call}, |
||||
{NppWarp<CV_32F, nppiWarpAffineBack_32f_C1R>::call, 0, NppWarp<CV_32F, nppiWarpAffineBack_32f_C3R>::call, NppWarp<CV_32F, nppiWarpAffineBack_32f_C4R>::call} |
||||
} |
||||
}; |
||||
|
||||
double coeffs[2][3]; |
||||
Mat coeffsMat(2, 3, CV_64F, (void*)coeffs); |
||||
M.convertTo(coeffsMat, coeffsMat.type()); |
||||
|
||||
const func_t func = funcs[(flags & WARP_INVERSE_MAP) != 0][src.depth()][src.channels() - 1]; |
||||
CV_Assert(func != 0); |
||||
|
||||
func(src, wholeSize, ofs, dst, coeffs, dsize, interpolation, StreamAccessor::getStream(s)); |
||||
} |
||||
else |
||||
{ |
||||
using namespace cv::gpu::device::imgproc; |
||||
|
||||
typedef void (*func_t)(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
static const func_t funcs[6][4] = |
||||
{ |
||||
{warpAffine_gpu<uchar> , 0 /*warpAffine_gpu<uchar2>*/ , warpAffine_gpu<uchar3> , warpAffine_gpu<uchar4> }, |
||||
{0 /*warpAffine_gpu<schar>*/, 0 /*warpAffine_gpu<char2>*/ , 0 /*warpAffine_gpu<char3>*/, 0 /*warpAffine_gpu<char4>*/}, |
||||
{warpAffine_gpu<ushort> , 0 /*warpAffine_gpu<ushort2>*/, warpAffine_gpu<ushort3> , warpAffine_gpu<ushort4> }, |
||||
{warpAffine_gpu<short> , 0 /*warpAffine_gpu<short2>*/ , warpAffine_gpu<short3> , warpAffine_gpu<short4> }, |
||||
{0 /*warpAffine_gpu<int>*/ , 0 /*warpAffine_gpu<int2>*/ , 0 /*warpAffine_gpu<int3>*/ , 0 /*warpAffine_gpu<int4>*/ }, |
||||
{warpAffine_gpu<float> , 0 /*warpAffine_gpu<float2>*/ , warpAffine_gpu<float3> , warpAffine_gpu<float4> } |
||||
}; |
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1]; |
||||
CV_Assert(func != 0); |
||||
|
||||
int gpuBorderType; |
||||
CV_Assert(tryConvertToGpuBorderType(borderMode, gpuBorderType)); |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
float coeffs[2 * 3]; |
||||
Mat coeffsMat(2, 3, CV_32F, (void*)coeffs); |
||||
|
||||
if (flags & WARP_INVERSE_MAP) |
||||
M.convertTo(coeffsMat, coeffsMat.type()); |
||||
else |
||||
{ |
||||
cv::Mat iM; |
||||
invertAffineTransform(M, iM); |
||||
iM.convertTo(coeffsMat, coeffsMat.type()); |
||||
} |
||||
|
||||
Scalar_<float> borderValueFloat; |
||||
borderValueFloat = borderValue; |
||||
|
||||
DeviceInfo info; |
||||
int cc = info.majorVersion() * 10 + info.minorVersion(); |
||||
|
||||
func(src, DevMem2Db(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, coeffs, |
||||
dst, interpolation, gpuBorderType, borderValueFloat.val, StreamAccessor::getStream(s), cc); |
||||
} |
||||
} |
||||
|
||||
void cv::gpu::warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& s) |
||||
{ |
||||
CV_Assert(M.rows == 3 && M.cols == 3); |
||||
|
||||
int interpolation = flags & INTER_MAX; |
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); |
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC); |
||||
CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP); |
||||
|
||||
Size wholeSize; |
||||
Point ofs; |
||||
src.locateROI(wholeSize, ofs); |
||||
|
||||
static const bool useNppTab[6][4][3] = |
||||
{ |
||||
{ |
||||
{false, false, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, true, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false}, |
||||
{false, false, false} |
||||
}, |
||||
{ |
||||
{false, true, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, true} |
||||
}, |
||||
{ |
||||
{false, true, true}, |
||||
{false, false, false}, |
||||
{false, true, true}, |
||||
{false, false, true} |
||||
} |
||||
}; |
||||
|
||||
bool useNpp = borderMode == BORDER_CONSTANT; |
||||
useNpp = useNpp && useNppTab[src.depth()][src.channels() - 1][interpolation]; |
||||
#ifdef linux |
||||
// NPP bug on float data
|
||||
useNpp = useNpp && src.depth() != CV_32F; |
||||
#endif |
||||
|
||||
if (useNpp) |
||||
{ |
||||
typedef void (*func_t)(const cv::gpu::GpuMat& src, cv::Size wholeSize, cv::Point ofs, cv::gpu::GpuMat& dst, double coeffs[][3], cv::Size dsize, int flags, cudaStream_t stream); |
||||
|
||||
static const func_t funcs[2][6][4] = |
||||
{ |
||||
{ |
||||
{NppWarp<CV_8U, nppiWarpPerspective_8u_C1R>::call, 0, NppWarp<CV_8U, nppiWarpPerspective_8u_C3R>::call, NppWarp<CV_8U, nppiWarpPerspective_8u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_16U, nppiWarpPerspective_16u_C1R>::call, 0, NppWarp<CV_16U, nppiWarpPerspective_16u_C3R>::call, NppWarp<CV_16U, nppiWarpPerspective_16u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_32S, nppiWarpPerspective_32s_C1R>::call, 0, NppWarp<CV_32S, nppiWarpPerspective_32s_C3R>::call, NppWarp<CV_32S, nppiWarpPerspective_32s_C4R>::call}, |
||||
{NppWarp<CV_32F, nppiWarpPerspective_32f_C1R>::call, 0, NppWarp<CV_32F, nppiWarpPerspective_32f_C3R>::call, NppWarp<CV_32F, nppiWarpPerspective_32f_C4R>::call} |
||||
}, |
||||
{ |
||||
{NppWarp<CV_8U, nppiWarpPerspectiveBack_8u_C1R>::call, 0, NppWarp<CV_8U, nppiWarpPerspectiveBack_8u_C3R>::call, NppWarp<CV_8U, nppiWarpPerspectiveBack_8u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_16U, nppiWarpPerspectiveBack_16u_C1R>::call, 0, NppWarp<CV_16U, nppiWarpPerspectiveBack_16u_C3R>::call, NppWarp<CV_16U, nppiWarpPerspectiveBack_16u_C4R>::call}, |
||||
{0, 0, 0, 0}, |
||||
{NppWarp<CV_32S, nppiWarpPerspectiveBack_32s_C1R>::call, 0, NppWarp<CV_32S, nppiWarpPerspectiveBack_32s_C3R>::call, NppWarp<CV_32S, nppiWarpPerspectiveBack_32s_C4R>::call}, |
||||
{NppWarp<CV_32F, nppiWarpPerspectiveBack_32f_C1R>::call, 0, NppWarp<CV_32F, nppiWarpPerspectiveBack_32f_C3R>::call, NppWarp<CV_32F, nppiWarpPerspectiveBack_32f_C4R>::call} |
||||
} |
||||
}; |
||||
|
||||
double coeffs[3][3]; |
||||
Mat coeffsMat(3, 3, CV_64F, (void*)coeffs); |
||||
M.convertTo(coeffsMat, coeffsMat.type()); |
||||
|
||||
const func_t func = funcs[(flags & WARP_INVERSE_MAP) != 0][src.depth()][src.channels() - 1]; |
||||
CV_Assert(func != 0); |
||||
|
||||
func(src, wholeSize, ofs, dst, coeffs, dsize, interpolation, StreamAccessor::getStream(s)); |
||||
} |
||||
else |
||||
{ |
||||
using namespace cv::gpu::device::imgproc; |
||||
|
||||
typedef void (*func_t)(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float coeffs[2 * 3], DevMem2Db dst, int interpolation, |
||||
int borderMode, const float* borderValue, cudaStream_t stream, int cc); |
||||
|
||||
static const func_t funcs[6][4] = |
||||
{ |
||||
{warpPerspective_gpu<uchar> , 0 /*warpPerspective_gpu<uchar2>*/ , warpPerspective_gpu<uchar3> , warpPerspective_gpu<uchar4> }, |
||||
{0 /*warpPerspective_gpu<schar>*/, 0 /*warpPerspective_gpu<char2>*/ , 0 /*warpPerspective_gpu<char3>*/, 0 /*warpPerspective_gpu<char4>*/}, |
||||
{warpPerspective_gpu<ushort> , 0 /*warpPerspective_gpu<ushort2>*/, warpPerspective_gpu<ushort3> , warpPerspective_gpu<ushort4> }, |
||||
{warpPerspective_gpu<short> , 0 /*warpPerspective_gpu<short2>*/ , warpPerspective_gpu<short3> , warpPerspective_gpu<short4> }, |
||||
{0 /*warpPerspective_gpu<int>*/ , 0 /*warpPerspective_gpu<int2>*/ , 0 /*warpPerspective_gpu<int3>*/ , 0 /*warpPerspective_gpu<int4>*/ }, |
||||
{warpPerspective_gpu<float> , 0 /*warpPerspective_gpu<float2>*/ , warpPerspective_gpu<float3> , warpPerspective_gpu<float4> } |
||||
}; |
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1]; |
||||
CV_Assert(func != 0); |
||||
|
||||
int gpuBorderType; |
||||
CV_Assert(tryConvertToGpuBorderType(borderMode, gpuBorderType)); |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
float coeffs[3 * 3]; |
||||
Mat coeffsMat(3, 3, CV_32F, (void*)coeffs); |
||||
|
||||
if (flags & WARP_INVERSE_MAP) |
||||
M.convertTo(coeffsMat, coeffsMat.type()); |
||||
else |
||||
{ |
||||
cv::Mat iM; |
||||
invert(M, iM); |
||||
iM.convertTo(coeffsMat, coeffsMat.type()); |
||||
} |
||||
|
||||
Scalar_<float> borderValueFloat; |
||||
borderValueFloat = borderValue; |
||||
|
||||
DeviceInfo info; |
||||
int cc = info.majorVersion() * 10 + info.minorVersion(); |
||||
|
||||
func(src, DevMem2Db(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, coeffs, |
||||
dst, interpolation, gpuBorderType, borderValueFloat.val, StreamAccessor::getStream(s), cc); |
||||
} |
||||
} |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,120 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_TEST_INTERPOLATION_HPP__ |
||||
#define __OPENCV_TEST_INTERPOLATION_HPP__ |
||||
|
||||
template <typename T> T readVal(const cv::Mat& src, int y, int x, int c, int border_type, cv::Scalar borderVal = cv::Scalar()) |
||||
{ |
||||
if (border_type == cv::BORDER_CONSTANT) |
||||
return (y >= 0 && y < src.rows && x >= 0 && x < src.cols) ? src.at<T>(y, x * src.channels() + c) : cv::saturate_cast<T>(borderVal.val[c]); |
||||
|
||||
return src.at<T>(cv::borderInterpolate(y, src.rows, border_type), cv::borderInterpolate(x, src.cols, border_type) * src.channels() + c); |
||||
} |
||||
|
||||
template <typename T> struct NearestInterpolator |
||||
{ |
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar()) |
||||
{ |
||||
return readVal<T>(src, cvFloor(y), cvFloor(x), c, border_type, borderVal); |
||||
} |
||||
}; |
||||
|
||||
template <typename T> struct LinearInterpolator |
||||
{ |
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar()) |
||||
{ |
||||
x -= 0.5f; |
||||
y -= 0.5f; |
||||
|
||||
int x1 = cvFloor(x); |
||||
int y1 = cvFloor(y); |
||||
int x2 = x1 + 1; |
||||
int y2 = y1 + 1; |
||||
|
||||
float res = 0; |
||||
|
||||
res += readVal<T>(src, y1, x1, c, border_type, borderVal) * ((x2 - x) * (y2 - y)); |
||||
res += readVal<T>(src, y1, x2, c, border_type, borderVal) * ((x - x1) * (y2 - y)); |
||||
res += readVal<T>(src, y2, x1, c, border_type, borderVal) * ((x2 - x) * (y - y1)); |
||||
res += readVal<T>(src, y2, x2, c, border_type, borderVal) * ((x - x1) * (y - y1)); |
||||
|
||||
return cv::saturate_cast<T>(res); |
||||
} |
||||
}; |
||||
|
||||
template <typename T> struct CubicInterpolator |
||||
{ |
||||
static float getValue(float p[4], float x) |
||||
{ |
||||
return p[1] + 0.5 * x * (p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0]))); |
||||
} |
||||
|
||||
static float getValue(float p[4][4], float x, float y) |
||||
{ |
||||
float arr[4]; |
||||
|
||||
arr[0] = getValue(p[0], x); |
||||
arr[1] = getValue(p[1], x); |
||||
arr[2] = getValue(p[2], x); |
||||
arr[3] = getValue(p[3], x); |
||||
|
||||
return getValue(arr, y); |
||||
} |
||||
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar()) |
||||
{ |
||||
int ix = cvRound(x); |
||||
int iy = cvRound(y); |
||||
|
||||
float vals[4][4] = |
||||
{ |
||||
{readVal<T>(src, iy - 2, ix - 2, c, border_type, borderVal), readVal<T>(src, iy - 2, ix - 1, c, border_type, borderVal), readVal<T>(src, iy - 2, ix, c, border_type, borderVal), readVal<T>(src, iy - 2, ix + 1, c, border_type, borderVal)}, |
||||
{readVal<T>(src, iy - 1, ix - 2, c, border_type, borderVal), readVal<T>(src, iy - 1, ix - 1, c, border_type, borderVal), readVal<T>(src, iy - 1, ix, c, border_type, borderVal), readVal<T>(src, iy - 1, ix + 1, c, border_type, borderVal)}, |
||||
{readVal<T>(src, iy , ix - 2, c, border_type, borderVal), readVal<T>(src, iy , ix - 1, c, border_type, borderVal), readVal<T>(src, iy , ix, c, border_type, borderVal), readVal<T>(src, iy , ix + 1, c, border_type, borderVal)}, |
||||
{readVal<T>(src, iy + 1, ix - 2, c, border_type, borderVal), readVal<T>(src, iy + 1, ix - 1, c, border_type, borderVal), readVal<T>(src, iy + 1, ix, c, border_type, borderVal), readVal<T>(src, iy + 1, ix + 1, c, border_type, borderVal)}, |
||||
}; |
||||
|
||||
return cv::saturate_cast<T>(getValue(vals, (x - ix + 2.0) / 4.0, (y - iy + 2.0) / 4.0)); |
||||
} |
||||
}; |
||||
|
||||
#endif // __OPENCV_TEST_INTERPOLATION_HPP__
|
@ -0,0 +1,90 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
PARAM_TEST_CASE(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, int, Border, UseRoi) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
int type; |
||||
int border; |
||||
int borderType; |
||||
bool useRoi; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
type = GET_PARAM(2); |
||||
border = GET_PARAM(3); |
||||
borderType = GET_PARAM(4); |
||||
useRoi = GET_PARAM(5); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(CopyMakeBorder, Accuracy) |
||||
{ |
||||
cv::Mat src = randomMat(size, type); |
||||
cv::Scalar val = randomScalar(0, 255); |
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi); |
||||
cv::gpu::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val); |
||||
|
||||
cv::Mat dst_gold; |
||||
cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine( |
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
testing::Values(1, 10, 50), |
||||
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_CONSTANT), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), |
||||
WHOLE_SUBMAT)); |
||||
|
||||
#endif // HAVE_CUDA
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,177 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace |
||||
{ |
||||
template <typename T, template <typename> class Interpolator> void remapImpl(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int borderType, cv::Scalar borderVal) |
||||
{ |
||||
const int cn = src.channels(); |
||||
|
||||
cv::Size dsize = xmap.size(); |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
for (int y = 0; y < dsize.height; ++y) |
||||
{ |
||||
for (int x = 0; x < dsize.width; ++x) |
||||
{ |
||||
for (int c = 0; c < cn; ++c) |
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ymap.at<float>(y, x), xmap.at<float>(y, x), c, borderType, borderVal); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void remapGold(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal) |
||||
{ |
||||
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& xmap, const cv::Mat& ymap, cv::Mat& dst, int borderType, cv::Scalar borderVal); |
||||
|
||||
static const func_t nearest_funcs[] =
|
||||
{ |
||||
remapImpl<unsigned char, NearestInterpolator>, |
||||
remapImpl<signed char, NearestInterpolator>, |
||||
remapImpl<unsigned short, NearestInterpolator>, |
||||
remapImpl<short, NearestInterpolator>, |
||||
remapImpl<int, NearestInterpolator>, |
||||
remapImpl<float, NearestInterpolator> |
||||
}; |
||||
|
||||
static const func_t linear_funcs[] =
|
||||
{ |
||||
remapImpl<unsigned char, LinearInterpolator>, |
||||
remapImpl<signed char, LinearInterpolator>, |
||||
remapImpl<unsigned short, LinearInterpolator>, |
||||
remapImpl<short, LinearInterpolator>, |
||||
remapImpl<int, LinearInterpolator>, |
||||
remapImpl<float, LinearInterpolator> |
||||
}; |
||||
|
||||
static const func_t cubic_funcs[] =
|
||||
{ |
||||
remapImpl<unsigned char, CubicInterpolator>, |
||||
remapImpl<signed char, CubicInterpolator>, |
||||
remapImpl<unsigned short, CubicInterpolator>, |
||||
remapImpl<short, CubicInterpolator>, |
||||
remapImpl<int, CubicInterpolator>, |
||||
remapImpl<float, CubicInterpolator> |
||||
}; |
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs}; |
||||
|
||||
funcs[interpolation][src.depth()](src, xmap, ymap, dst, borderType, borderVal); |
||||
} |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, Border, UseRoi) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
int type; |
||||
int interpolation; |
||||
int borderType; |
||||
bool useRoi; |
||||
|
||||
cv::Mat xmap; |
||||
cv::Mat ymap; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
type = GET_PARAM(2); |
||||
interpolation = GET_PARAM(3); |
||||
borderType = GET_PARAM(4); |
||||
useRoi = GET_PARAM(5); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
|
||||
// rotation matrix
|
||||
|
||||
const double aplha = CV_PI / 4; |
||||
static double M[2][3] = { {std::cos(aplha), -std::sin(aplha), size.width / 2.0}, |
||||
{std::sin(aplha), std::cos(aplha), 0.0}}; |
||||
|
||||
xmap.create(size, CV_32FC1); |
||||
ymap.create(size, CV_32FC1); |
||||
|
||||
for (int y = 0; y < size.height; ++y) |
||||
{ |
||||
for (int x = 0; x < size.width; ++x) |
||||
{ |
||||
xmap.at<float>(y, x) = static_cast<float>(M[0][0] * x + M[0][1] * y + M[0][2]); |
||||
ymap.at<float>(y, x) = static_cast<float>(M[1][0] * x + M[1][1] * y + M[1][2]); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
TEST_P(Remap, Accuracy) |
||||
{ |
||||
cv::Mat src = randomMat(size, type); |
||||
cv::Scalar val = randomScalar(0.0, 255.0); |
||||
|
||||
cv::gpu::GpuMat dst = createMat(xmap.size(), type, useRoi); |
||||
cv::gpu::remap(loadMat(src, useRoi), dst, loadMat(xmap, useRoi), loadMat(ymap, useRoi), interpolation, borderType, val); |
||||
|
||||
cv::Mat dst_gold; |
||||
remapGold(src, xmap, ymap, dst_gold, interpolation, borderType, val); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Remap, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), |
||||
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_CONSTANT), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), |
||||
WHOLE_SUBMAT)); |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,202 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace |
||||
{ |
||||
template <typename T, template <typename> class Interpolator> void resizeImpl(const cv::Mat& src, cv::Mat& dst, double fx, double fy) |
||||
{ |
||||
const int cn = src.channels(); |
||||
|
||||
cv::Size dsize(cv::saturate_cast<int>(src.cols * fx), cv::saturate_cast<int>(src.rows * fy)); |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
float ifx = static_cast<float>(1.0 / fx); |
||||
float ify = static_cast<float>(1.0 / fy); |
||||
|
||||
for (int y = 0; y < dsize.height; ++y) |
||||
{ |
||||
for (int x = 0; x < dsize.width; ++x) |
||||
{ |
||||
for (int c = 0; c < cn; ++c) |
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, y * ify, x * ifx, c, cv::BORDER_REPLICATE); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void resizeGold(const cv::Mat& src, cv::Mat& dst, double fx, double fy, int interpolation) |
||||
{ |
||||
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst, double fx, double fy); |
||||
|
||||
static const func_t nearest_funcs[] = |
||||
{ |
||||
resizeImpl<unsigned char, NearestInterpolator>, |
||||
resizeImpl<signed char, NearestInterpolator>, |
||||
resizeImpl<unsigned short, NearestInterpolator>, |
||||
resizeImpl<short, NearestInterpolator>, |
||||
resizeImpl<int, NearestInterpolator>, |
||||
resizeImpl<float, NearestInterpolator> |
||||
}; |
||||
|
||||
|
||||
static const func_t linear_funcs[] = |
||||
{ |
||||
resizeImpl<unsigned char, LinearInterpolator>, |
||||
resizeImpl<signed char, LinearInterpolator>, |
||||
resizeImpl<unsigned short, LinearInterpolator>, |
||||
resizeImpl<short, LinearInterpolator>, |
||||
resizeImpl<int, LinearInterpolator>, |
||||
resizeImpl<float, LinearInterpolator> |
||||
}; |
||||
|
||||
static const func_t cubic_funcs[] = |
||||
{ |
||||
resizeImpl<unsigned char, CubicInterpolator>, |
||||
resizeImpl<signed char, CubicInterpolator>, |
||||
resizeImpl<unsigned short, CubicInterpolator>, |
||||
resizeImpl<short, CubicInterpolator>, |
||||
resizeImpl<int, CubicInterpolator>, |
||||
resizeImpl<float, CubicInterpolator> |
||||
}; |
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs}; |
||||
|
||||
funcs[interpolation][src.depth()](src, dst, fx, fy); |
||||
} |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
double coeff; |
||||
int interpolation; |
||||
int type; |
||||
bool useRoi; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
type = GET_PARAM(2); |
||||
coeff = GET_PARAM(3); |
||||
interpolation = GET_PARAM(4); |
||||
useRoi = GET_PARAM(5); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(Resize, Accuracy) |
||||
{ |
||||
cv::Mat src = randomMat(size, type); |
||||
|
||||
cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi); |
||||
cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation); |
||||
|
||||
cv::Mat dst_gold; |
||||
resizeGold(src, dst_gold, coeff, coeff, interpolation); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
testing::Values(0.3, 0.5, 1.5, 2.0), |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), |
||||
WHOLE_SUBMAT)); |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test NPP
|
||||
|
||||
PARAM_TEST_CASE(ResizeNPP, cv::gpu::DeviceInfo, MatType, double, Interpolation) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
double coeff; |
||||
int interpolation; |
||||
int type; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
type = GET_PARAM(1); |
||||
coeff = GET_PARAM(2); |
||||
interpolation = GET_PARAM(3); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(ResizeNPP, Accuracy) |
||||
{ |
||||
if (type == CV_8UC1 && interpolation == cv::INTER_CUBIC) |
||||
return; |
||||
|
||||
cv::Mat src = readImageType("stereobp/aloe-L.png", type); |
||||
|
||||
cv::gpu::GpuMat dst; |
||||
cv::gpu::resize(loadMat(src), dst, cv::Size(), coeff, coeff, interpolation); |
||||
|
||||
cv::Mat dst_gold; |
||||
resizeGold(src, dst_gold, coeff, coeff, interpolation); |
||||
|
||||
EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-1); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeNPP, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)), |
||||
testing::Values(0.3, 0.5, 1.5, 2.0), |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)))); |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,88 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
PARAM_TEST_CASE(Threshold, cv::gpu::DeviceInfo, cv::Size, MatType, ThreshOp, UseRoi) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
int type; |
||||
int threshOp; |
||||
bool useRoi; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
type = GET_PARAM(2); |
||||
threshOp = GET_PARAM(3); |
||||
useRoi = GET_PARAM(4); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(Threshold, Accuracy) |
||||
{ |
||||
cv::Mat src = randomMat(size, type); |
||||
double maxVal = randomDouble(20.0, 127.0); |
||||
double thresh = randomDouble(0.0, maxVal); |
||||
|
||||
cv::gpu::GpuMat dst = createMat(src.size(), src.type(), useRoi); |
||||
cv::gpu::threshold(loadMat(src, useRoi), dst, thresh, maxVal, threshOp); |
||||
|
||||
cv::Mat dst_gold; |
||||
cv::threshold(src, dst_gold, thresh, maxVal, threshOp); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Threshold, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_16SC1), MatType(CV_32FC1)), |
||||
testing::Values(ThreshOp(cv::THRESH_BINARY), ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV)), |
||||
WHOLE_SUBMAT)); |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,275 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
namespace |
||||
{ |
||||
cv::Mat createTransfomMatrix(cv::Size srcSize, double angle) |
||||
{ |
||||
cv::Mat M(2, 3, CV_64FC1); |
||||
M.at<double>(0, 0) = std::cos(angle); M.at<double>(0, 1) = -std::sin(angle); M.at<double>(0, 2) = srcSize.width / 2; |
||||
M.at<double>(1, 0) = std::sin(angle); M.at<double>(1, 1) = std::cos(angle); M.at<double>(1, 2) = 0.0; |
||||
|
||||
return M; |
||||
} |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test buildWarpAffineMaps
|
||||
|
||||
PARAM_TEST_CASE(BuildWarpAffineMaps, cv::gpu::DeviceInfo, cv::Size, Inverse) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
bool inverse; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
inverse = GET_PARAM(2); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(BuildWarpAffineMaps, Accuracy) |
||||
{ |
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 4); |
||||
cv::gpu::GpuMat xmap, ymap; |
||||
cv::gpu::buildWarpAffineMaps(M, inverse, size, xmap, ymap); |
||||
|
||||
int interpolation = cv::INTER_NEAREST; |
||||
int borderMode = cv::BORDER_CONSTANT; |
||||
|
||||
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1); |
||||
cv::Mat dst; |
||||
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode); |
||||
|
||||
int flags = interpolation; |
||||
if (inverse) |
||||
flags |= cv::WARP_INVERSE_MAP; |
||||
cv::Mat dst_gold; |
||||
cv::warpAffine(src, dst_gold, M, size, flags, borderMode); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpAffineMaps, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
DIRECT_INVERSE)); |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace |
||||
{ |
||||
template <typename T, template <typename> class Interpolator> void warpAffineImpl(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal) |
||||
{ |
||||
const int cn = src.channels(); |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
for (int y = 0; y < dsize.height; ++y) |
||||
{ |
||||
for (int x = 0; x < dsize.width; ++x) |
||||
{ |
||||
float xcoo = static_cast<float>(M.at<double>(0, 0) * x + M.at<double>(0, 1) * y + M.at<double>(0, 2)); |
||||
float ycoo = static_cast<float>(M.at<double>(1, 0) * x + M.at<double>(1, 1) * y + M.at<double>(1, 2)); |
||||
|
||||
for (int c = 0; c < cn; ++c) |
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ycoo, xcoo, c, borderType, borderVal); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void warpAffineGold(const cv::Mat& src, const cv::Mat& M, bool inverse, cv::Size dsize, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal) |
||||
{ |
||||
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal); |
||||
|
||||
static const func_t nearest_funcs[] = |
||||
{ |
||||
warpAffineImpl<unsigned char, NearestInterpolator>, |
||||
warpAffineImpl<signed char, NearestInterpolator>, |
||||
warpAffineImpl<unsigned short, NearestInterpolator>, |
||||
warpAffineImpl<short, NearestInterpolator>, |
||||
warpAffineImpl<int, NearestInterpolator>, |
||||
warpAffineImpl<float, NearestInterpolator> |
||||
}; |
||||
|
||||
static const func_t linear_funcs[] = |
||||
{ |
||||
warpAffineImpl<unsigned char, LinearInterpolator>, |
||||
warpAffineImpl<signed char, LinearInterpolator>, |
||||
warpAffineImpl<unsigned short, LinearInterpolator>, |
||||
warpAffineImpl<short, LinearInterpolator>, |
||||
warpAffineImpl<int, LinearInterpolator>, |
||||
warpAffineImpl<float, LinearInterpolator> |
||||
}; |
||||
|
||||
static const func_t cubic_funcs[] = |
||||
{ |
||||
warpAffineImpl<unsigned char, CubicInterpolator>, |
||||
warpAffineImpl<signed char, CubicInterpolator>, |
||||
warpAffineImpl<unsigned short, CubicInterpolator>, |
||||
warpAffineImpl<short, CubicInterpolator>, |
||||
warpAffineImpl<int, CubicInterpolator>, |
||||
warpAffineImpl<float, CubicInterpolator> |
||||
}; |
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs}; |
||||
|
||||
if (inverse) |
||||
funcs[interpolation][src.depth()](src, M, dsize, dst, borderType, borderVal); |
||||
else |
||||
{ |
||||
cv::Mat iM; |
||||
cv::invertAffineTransform(M, iM); |
||||
funcs[interpolation][src.depth()](src, iM, dsize, dst, borderType, borderVal); |
||||
} |
||||
} |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, Border, UseRoi) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
int type; |
||||
bool inverse; |
||||
int interpolation; |
||||
int borderType; |
||||
bool useRoi; |
||||
|
||||
cv::Mat M; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
type = GET_PARAM(2); |
||||
inverse = GET_PARAM(3); |
||||
interpolation = GET_PARAM(4); |
||||
borderType = GET_PARAM(5); |
||||
useRoi = GET_PARAM(6); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(WarpAffine, Accuracy) |
||||
{ |
||||
cv::Mat src = randomMat(size, type); |
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 3); |
||||
int flags = interpolation; |
||||
if (inverse) |
||||
flags |= cv::WARP_INVERSE_MAP; |
||||
cv::Scalar val = randomScalar(0.0, 255.0); |
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi); |
||||
cv::gpu::warpAffine(loadMat(src, useRoi), dst, M, size, flags, borderType, val); |
||||
|
||||
cv::Mat dst_gold; |
||||
warpAffineGold(src, M, inverse, size, dst_gold, interpolation, borderType, val); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffine, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
DIRECT_INVERSE, |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), |
||||
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), |
||||
WHOLE_SUBMAT)); |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test NPP
|
||||
|
||||
PARAM_TEST_CASE(WarpAffineNPP, cv::gpu::DeviceInfo, MatType, Inverse, Interpolation) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
int type; |
||||
bool inverse; |
||||
int interpolation; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
type = GET_PARAM(1); |
||||
inverse = GET_PARAM(2); |
||||
interpolation = GET_PARAM(3); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(WarpAffineNPP, Accuracy) |
||||
{ |
||||
cv::Mat src = readImageType("stereobp/aloe-L.png", type); |
||||
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4); |
||||
int flags = interpolation; |
||||
if (inverse) |
||||
flags |= cv::WARP_INVERSE_MAP; |
||||
|
||||
cv::gpu::GpuMat dst; |
||||
cv::gpu::warpAffine(loadMat(src), dst, M, src.size(), flags); |
||||
|
||||
cv::Mat dst_gold; |
||||
warpAffineGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0)); |
||||
|
||||
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffineNPP, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
DIRECT_INVERSE, |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)))); |
||||
|
||||
#endif // HAVE_CUDA
|
@ -0,0 +1,275 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
namespace |
||||
{ |
||||
cv::Mat createTransfomMatrix(cv::Size srcSize, double angle) |
||||
{ |
||||
cv::Mat M(3, 3, CV_64FC1); |
||||
M.at<double>(0, 0) = std::cos(angle); M.at<double>(0, 1) = -std::sin(angle); M.at<double>(0, 2) = srcSize.width / 2; |
||||
M.at<double>(1, 0) = std::sin(angle); M.at<double>(1, 1) = std::cos(angle); M.at<double>(1, 2) = 0.0; |
||||
M.at<double>(2, 0) = 0.0 ; M.at<double>(2, 1) = 0.0 ; M.at<double>(2, 2) = 1.0; |
||||
|
||||
return M; |
||||
} |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test buildWarpPerspectiveMaps
|
||||
|
||||
PARAM_TEST_CASE(BuildWarpPerspectiveMaps, cv::gpu::DeviceInfo, cv::Size, Inverse) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
bool inverse; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
inverse = GET_PARAM(2); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(BuildWarpPerspectiveMaps, Accuracy) |
||||
{ |
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 4); |
||||
cv::gpu::GpuMat xmap, ymap; |
||||
cv::gpu::buildWarpPerspectiveMaps(M, inverse, size, xmap, ymap); |
||||
|
||||
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1); |
||||
cv::Mat dst; |
||||
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), cv::INTER_NEAREST, cv::BORDER_CONSTANT); |
||||
|
||||
int flags = cv::INTER_NEAREST; |
||||
if (inverse) |
||||
flags |= cv::WARP_INVERSE_MAP; |
||||
cv::Mat dst_gold; |
||||
cv::warpPerspective(src, dst_gold, M, size, flags, cv::BORDER_CONSTANT); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpPerspectiveMaps, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
DIRECT_INVERSE)); |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Gold implementation
|
||||
|
||||
namespace |
||||
{ |
||||
template <typename T, template <typename> class Interpolator> void warpPerspectiveImpl(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal) |
||||
{ |
||||
const int cn = src.channels(); |
||||
|
||||
dst.create(dsize, src.type()); |
||||
|
||||
for (int y = 0; y < dsize.height; ++y) |
||||
{ |
||||
for (int x = 0; x < dsize.width; ++x) |
||||
{ |
||||
float coeff = static_cast<float>(M.at<double>(2, 0) * x + M.at<double>(2, 1) * y + M.at<double>(2, 2)); |
||||
|
||||
float xcoo = static_cast<float>((M.at<double>(0, 0) * x + M.at<double>(0, 1) * y + M.at<double>(0, 2)) / coeff); |
||||
float ycoo = static_cast<float>((M.at<double>(1, 0) * x + M.at<double>(1, 1) * y + M.at<double>(1, 2)) / coeff); |
||||
|
||||
for (int c = 0; c < cn; ++c) |
||||
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, ycoo, xcoo, c, borderType, borderVal); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void warpPerspectiveGold(const cv::Mat& src, const cv::Mat& M, bool inverse, cv::Size dsize, cv::Mat& dst, int interpolation, int borderType, cv::Scalar borderVal) |
||||
{ |
||||
typedef void (*func_t)(const cv::Mat& src, const cv::Mat& M, cv::Size dsize, cv::Mat& dst, int borderType, cv::Scalar borderVal); |
||||
|
||||
static const func_t nearest_funcs[] = |
||||
{ |
||||
warpPerspectiveImpl<unsigned char, NearestInterpolator>, |
||||
warpPerspectiveImpl<signed char, NearestInterpolator>, |
||||
warpPerspectiveImpl<unsigned short, NearestInterpolator>, |
||||
warpPerspectiveImpl<short, NearestInterpolator>, |
||||
warpPerspectiveImpl<int, NearestInterpolator>, |
||||
warpPerspectiveImpl<float, NearestInterpolator> |
||||
}; |
||||
|
||||
static const func_t linear_funcs[] = |
||||
{ |
||||
warpPerspectiveImpl<unsigned char, LinearInterpolator>, |
||||
warpPerspectiveImpl<signed char, LinearInterpolator>, |
||||
warpPerspectiveImpl<unsigned short, LinearInterpolator>, |
||||
warpPerspectiveImpl<short, LinearInterpolator>, |
||||
warpPerspectiveImpl<int, LinearInterpolator>, |
||||
warpPerspectiveImpl<float, LinearInterpolator> |
||||
}; |
||||
|
||||
static const func_t cubic_funcs[] = |
||||
{ |
||||
warpPerspectiveImpl<unsigned char, CubicInterpolator>, |
||||
warpPerspectiveImpl<signed char, CubicInterpolator>, |
||||
warpPerspectiveImpl<unsigned short, CubicInterpolator>, |
||||
warpPerspectiveImpl<short, CubicInterpolator>, |
||||
warpPerspectiveImpl<int, CubicInterpolator>, |
||||
warpPerspectiveImpl<float, CubicInterpolator> |
||||
}; |
||||
|
||||
static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs}; |
||||
|
||||
if (inverse) |
||||
funcs[interpolation][src.depth()](src, M, dsize, dst, borderType, borderVal); |
||||
else |
||||
{ |
||||
cv::Mat iM; |
||||
cv::invert(M, iM); |
||||
funcs[interpolation][src.depth()](src, iM, dsize, dst, borderType, borderVal); |
||||
} |
||||
} |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test
|
||||
|
||||
PARAM_TEST_CASE(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Interpolation, Border, UseRoi) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
cv::Size size; |
||||
int type; |
||||
bool inverse; |
||||
int interpolation; |
||||
int borderType; |
||||
bool useRoi; |
||||
|
||||
cv::Mat M; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
size = GET_PARAM(1); |
||||
type = GET_PARAM(2); |
||||
inverse = GET_PARAM(3); |
||||
interpolation = GET_PARAM(4); |
||||
borderType = GET_PARAM(5); |
||||
useRoi = GET_PARAM(6); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(WarpPerspective, Accuracy) |
||||
{ |
||||
cv::Mat src = randomMat(size, type); |
||||
cv::Mat M = createTransfomMatrix(size, CV_PI / 3); |
||||
int flags = interpolation; |
||||
if (inverse) |
||||
flags |= cv::WARP_INVERSE_MAP; |
||||
cv::Scalar val = randomScalar(0.0, 255.0); |
||||
|
||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi); |
||||
cv::gpu::warpPerspective(loadMat(src, useRoi), dst, M, size, flags, borderType, val); |
||||
|
||||
cv::Mat dst_gold; |
||||
warpPerspectiveGold(src, M, inverse, size, dst_gold, interpolation, borderType, val); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspective, testing::Combine( |
||||
ALL_DEVICES, |
||||
DIFFERENT_SIZES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
DIRECT_INVERSE, |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), |
||||
testing::Values(Border(cv::BORDER_REFLECT101), Border(cv::BORDER_REPLICATE), Border(cv::BORDER_REFLECT), Border(cv::BORDER_WRAP)), |
||||
WHOLE_SUBMAT)); |
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Test NPP
|
||||
|
||||
PARAM_TEST_CASE(WarpPerspectiveNPP, cv::gpu::DeviceInfo, MatType, Inverse, Interpolation) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
int type; |
||||
bool inverse; |
||||
int interpolation; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
type = GET_PARAM(1); |
||||
inverse = GET_PARAM(2); |
||||
interpolation = GET_PARAM(3); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(WarpPerspectiveNPP, Accuracy) |
||||
{ |
||||
cv::Mat src = readImageType("stereobp/aloe-L.png", type); |
||||
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4); |
||||
int flags = interpolation; |
||||
if (inverse) |
||||
flags |= cv::WARP_INVERSE_MAP; |
||||
|
||||
cv::gpu::GpuMat dst; |
||||
cv::gpu::warpPerspective(loadMat(src), dst, M, src.size(), flags); |
||||
|
||||
cv::Mat dst_gold; |
||||
warpPerspectiveGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0)); |
||||
|
||||
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspectiveNPP, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), |
||||
DIRECT_INVERSE, |
||||
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)))); |
||||
|
||||
#endif // HAVE_CUDA
|
Loading…
Reference in new issue