提交 af59a75f 编写于 作者: V Vladislav Vinogradov

fixed bug with submatrix in some gpu functions

update gpu tests
上级 2ce6dd68
......@@ -59,56 +59,27 @@ namespace cv { namespace gpu { namespace device
////////////////////////////////// CopyTo /////////////////////////////////
///////////////////////////////////////////////////////////////////////////
template<typename T>
__global__ void copy_to_with_mask(const T* mat_src, T* mat_dst, const uchar* mask, int cols, int rows, size_t step_mat, size_t step_mask, int channels)
{
size_t x = blockIdx.x * blockDim.x + threadIdx.x;
size_t y = blockIdx.y * blockDim.y + threadIdx.y;
if ((x < cols * channels ) && (y < rows))
if (mask[y * step_mask + x / channels] != 0)
{
size_t idx = y * ( step_mat >> shift_and_sizeof<T>::shift ) + x;
mat_dst[idx] = mat_src[idx];
}
}
template<typename T>
void copy_to_with_mask_run(DevMem2Db mat_src, DevMem2Db mat_dst, DevMem2Db mask, int channels, cudaStream_t stream)
{
dim3 threadsPerBlock(16,16, 1);
dim3 numBlocks ( divUp(mat_src.cols * channels , threadsPerBlock.x) , divUp(mat_src.rows , threadsPerBlock.y), 1);
copy_to_with_mask<T><<<numBlocks,threadsPerBlock, 0, stream>>>
((T*)mat_src.data, (T*)mat_dst.data, (unsigned char*)mask.data, mat_src.cols, mat_src.rows, mat_src.step, mask.step, channels);
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
cudaSafeCall ( cudaDeviceSynchronize() );
template <typename T> void copyToWithMask(DevMem2Db src, DevMem2Db dst, DevMem2Db mask, int channels, cudaStream_t stream)
{
cv::gpu::device::transform((DevMem2D_<T>)src, (DevMem2D_<T>)dst, identity<T>(), SingleMaskChannels(mask, channels), stream);
}
void copy_to_with_mask(DevMem2Db mat_src, DevMem2Db mat_dst, int depth, DevMem2Db mask, int channels, cudaStream_t stream)
void copyToWithMask_gpu(DevMem2Db src, DevMem2Db dst, int depth, int channels, DevMem2Db mask, cudaStream_t stream)
{
typedef void (*CopyToFunc)(DevMem2Db mat_src, DevMem2Db mat_dst, DevMem2Db mask, int channels, cudaStream_t stream);
typedef void (*func_t)(DevMem2Db src, DevMem2Db dst, DevMem2Db mask, int channels, cudaStream_t stream);
static CopyToFunc tab[8] =
static func_t tab[] =
{
copy_to_with_mask_run<unsigned char>,
copy_to_with_mask_run<signed char>,
copy_to_with_mask_run<unsigned short>,
copy_to_with_mask_run<short>,
copy_to_with_mask_run<int>,
copy_to_with_mask_run<float>,
copy_to_with_mask_run<double>,
0
copyToWithMask<unsigned char>,
copyToWithMask<signed char>,
copyToWithMask<unsigned short>,
copyToWithMask<short>,
copyToWithMask<int>,
copyToWithMask<float>,
copyToWithMask<double>
};
CopyToFunc func = tab[depth];
if (func == 0)
cv::gpu::error("Unsupported copyTo operation", __FILE__, __LINE__, "copy_to_with_mask");
func(mat_src, mat_dst, mask, channels, stream);
tab[depth](src, dst, mask, channels, stream);
}
///////////////////////////////////////////////////////////////////////////
......@@ -303,7 +274,7 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaSetDoubleForDevice(&alpha) );
cudaSafeCall( cudaSetDoubleForDevice(&beta) );
Convertor<T, D> op(alpha, beta);
::cv::gpu::device::transform((DevMem2D_<T>)src, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
void convert_gpu(DevMem2Db src, int sdepth, DevMem2Db dst, int ddepth, double alpha, double beta, cudaStream_t stream)
......
......@@ -348,7 +348,7 @@ namespace
namespace cv { namespace gpu { namespace device
{
void copy_to_with_mask(DevMem2Db src, DevMem2Db dst, int depth, DevMem2Db mask, int channels, cudaStream_t stream);
void copyToWithMask_gpu(DevMem2Db src, DevMem2Db dst, int depth, int channels, DevMem2Db mask, cudaStream_t stream);
template <typename T>
void set_to_gpu(DevMem2Db mat, const T* scalar, int channels, cudaStream_t stream);
......@@ -391,13 +391,13 @@ namespace
template <typename T> void kernelSetCaller(GpuMat& src, Scalar s, cudaStream_t stream)
{
Scalar_<T> sf = s;
::cv::gpu::device::set_to_gpu(src, sf.val, src.channels(), stream);
cv::gpu::device::set_to_gpu(src, sf.val, src.channels(), stream);
}
template <typename T> void kernelSetCaller(GpuMat& src, Scalar s, const GpuMat& mask, cudaStream_t stream)
{
Scalar_<T> sf = s;
::cv::gpu::device::set_to_gpu(src, sf.val, mask, src.channels(), stream);
cv::gpu::device::set_to_gpu(src, sf.val, mask, src.channels(), stream);
}
}
......@@ -405,17 +405,17 @@ namespace cv { namespace gpu
{
CV_EXPORTS void copyWithMask(const GpuMat& src, GpuMat& dst, const GpuMat& mask, cudaStream_t stream = 0)
{
::cv::gpu::device::copy_to_with_mask(src, dst, src.depth(), mask, src.channels(), stream);
cv::gpu::device::copyToWithMask_gpu(src.reshape(1), dst.reshape(1), src.depth(), src.channels(), mask, stream);
}
CV_EXPORTS void convertTo(const GpuMat& src, GpuMat& dst)
{
::cv::gpu::device::convert_gpu(src.reshape(1), src.depth(), dst.reshape(1), dst.depth(), 1.0, 0.0, 0);
cv::gpu::device::convert_gpu(src.reshape(1), src.depth(), dst.reshape(1), dst.depth(), 1.0, 0.0, 0);
}
CV_EXPORTS void convertTo(const GpuMat& src, GpuMat& dst, double alpha, double beta, cudaStream_t stream = 0)
{
::cv::gpu::device::convert_gpu(src.reshape(1), src.depth(), dst.reshape(1), dst.depth(), alpha, beta, stream);
cv::gpu::device::convert_gpu(src.reshape(1), src.depth(), dst.reshape(1), dst.depth(), alpha, beta, stream);
}
CV_EXPORTS void setTo(GpuMat& src, Scalar s, cudaStream_t stream)
......
......@@ -74,7 +74,7 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall(cudaMemcpyToSymbol(crot1, rot + 3, sizeof(float) * 3));
cudaSafeCall(cudaMemcpyToSymbol(crot2, rot + 6, sizeof(float) * 3));
cudaSafeCall(cudaMemcpyToSymbol(ctransl, transl, sizeof(float) * 3));
::cv::gpu::device::transform(src, dst, TransformOp(), stream);
cv::gpu::device::transform(src, dst, TransformOp(), WithOutMask(), stream);
}
} // namespace transform_points
......@@ -113,7 +113,7 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall(cudaMemcpyToSymbol(ctransl, transl, sizeof(float) * 3));
cudaSafeCall(cudaMemcpyToSymbol(cproj0, proj, sizeof(float) * 3));
cudaSafeCall(cudaMemcpyToSymbol(cproj1, proj + 3, sizeof(float) * 3));
::cv::gpu::device::transform(src, dst, ProjectOp(), stream);
cv::gpu::device::transform(src, dst, ProjectOp(), WithOutMask(), stream);
}
} // namespace project_points
......
......@@ -226,7 +226,7 @@ namespace cv { namespace gpu { namespace device
traits::functor_type functor = traits::create_functor(); \
typedef typename traits::functor_type::argument_type src_t; \
typedef typename traits::functor_type::result_type dst_t; \
::cv::gpu::device::transform((DevMem2D_<src_t>)src, (DevMem2D_<dst_t>)dst, functor, stream); \
cv::gpu::device::transform((DevMem2D_<src_t>)src, (DevMem2D_<dst_t>)dst, functor, WithOutMask(), stream); \
}
#define OPENCV_GPU_IMPLEMENT_CVTCOLOR_ONE(name) \
......
......@@ -84,9 +84,9 @@ namespace cv { namespace gpu { namespace device
template <typename T, typename D> void add_gpu(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, const PtrStepb& mask, cudaStream_t stream)
{
if (mask.data)
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, mask, Add<T, D>(), stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, Add<T, D>(), SingleMask(mask), stream);
else
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, Add<T, D>(), stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, Add<T, D>(), WithOutMask(), stream);
}
template void add_gpu<uchar, uchar>(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, const PtrStepb& mask, cudaStream_t stream);
......@@ -181,9 +181,9 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaSetDoubleForDevice(&val) );
AddScalar<T, D> op(val);
if (mask.data)
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, mask, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, SingleMask(mask), stream);
else
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void add_gpu<uchar, uchar>(const DevMem2Db& src1, double val, const DevMem2Db& dst, const PtrStepb& mask, cudaStream_t stream);
......@@ -277,9 +277,9 @@ namespace cv { namespace gpu { namespace device
template <typename T, typename D> void subtract_gpu(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, const PtrStepb& mask, cudaStream_t stream)
{
if (mask.data)
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, mask, Subtract<T, D>(), stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, Subtract<T, D>(), SingleMask(mask), stream);
else
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, Subtract<T, D>(), stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, Subtract<T, D>(), WithOutMask(), stream);
}
template void subtract_gpu<uchar, uchar>(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, const PtrStepb& mask, cudaStream_t stream);
......@@ -374,9 +374,9 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaSetDoubleForDevice(&val) );
SubtractScalar<T, D> op(val);
if (mask.data)
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, mask, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, SingleMask(mask), stream);
else
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void subtract_gpu<uchar, uchar>(const DevMem2Db& src1, double val, const DevMem2Db& dst, const PtrStepb& mask, cudaStream_t stream);
......@@ -462,7 +462,7 @@ namespace cv { namespace gpu { namespace device
void multiply_gpu(const DevMem2D_<uchar4>& src1, const DevMem2Df& src2, const DevMem2D_<uchar4>& dst, cudaStream_t stream)
{
::cv::gpu::device::transform(static_cast< DevMem2D_<uint> >(src1), src2, static_cast< DevMem2D_<uint> >(dst), multiply_8uc4_32f(), stream);
cv::gpu::device::transform(static_cast< DevMem2D_<uint> >(src1), src2, static_cast< DevMem2D_<uint> >(dst), multiply_8uc4_32f(), WithOutMask(), stream);
}
struct multiply_16sc4_32f : binary_function<short4, float, short4>
......@@ -483,7 +483,7 @@ namespace cv { namespace gpu { namespace device
void multiply_gpu(const DevMem2D_<short4>& src1, const DevMem2Df& src2, const DevMem2D_<short4>& dst, cudaStream_t stream)
{
::cv::gpu::device::transform(static_cast< DevMem2D_<short4> >(src1), src2, static_cast< DevMem2D_<short4> >(dst), multiply_16sc4_32f(), stream);
cv::gpu::device::transform(static_cast< DevMem2D_<short4> >(src1), src2, static_cast< DevMem2D_<short4> >(dst), multiply_16sc4_32f(), WithOutMask(), stream);
}
template <typename T, typename D> struct Multiply : binary_function<T, T, D>
......@@ -521,7 +521,7 @@ namespace cv { namespace gpu { namespace device
{
cudaSafeCall( cudaSetDoubleForDevice(&scale) );
Multiply<T, D> op(scale);
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void multiply_gpu<uchar, uchar >(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, double scale, cudaStream_t stream);
......@@ -617,7 +617,7 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaSetDoubleForDevice(&val) );
cudaSafeCall( cudaSetDoubleForDevice(&scale) );
MultiplyScalar<T, D> op(val, scale);
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void multiply_gpu<uchar, uchar >(const DevMem2Db& src1, double val, const DevMem2Db& dst, double scale, cudaStream_t stream);
......@@ -698,7 +698,7 @@ namespace cv { namespace gpu { namespace device
void divide_gpu(const DevMem2D_<uchar4>& src1, const DevMem2Df& src2, const DevMem2D_<uchar4>& dst, cudaStream_t stream)
{
transform(static_cast< DevMem2D_<uchar4> >(src1), src2, static_cast< DevMem2D_<uchar4> >(dst), divide_8uc4_32f(), stream);
cv::gpu::device::transform(static_cast< DevMem2D_<uchar4> >(src1), src2, static_cast< DevMem2D_<uchar4> >(dst), divide_8uc4_32f(), WithOutMask(), stream);
}
......@@ -721,7 +721,7 @@ namespace cv { namespace gpu { namespace device
void divide_gpu(const DevMem2D_<short4>& src1, const DevMem2Df& src2, const DevMem2D_<short4>& dst, cudaStream_t stream)
{
transform(static_cast< DevMem2D_<short4> >(src1), src2, static_cast< DevMem2D_<short4> >(dst), divide_16sc4_32f(), stream);
cv::gpu::device::transform(static_cast< DevMem2D_<short4> >(src1), src2, static_cast< DevMem2D_<short4> >(dst), divide_16sc4_32f(), WithOutMask(), stream);
}
template <typename T, typename D> struct Divide : binary_function<T, T, D>
......@@ -759,7 +759,7 @@ namespace cv { namespace gpu { namespace device
{
cudaSafeCall( cudaSetDoubleForDevice(&scale) );
Divide<T, D> op(scale);
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void divide_gpu<uchar, uchar >(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, double scale, cudaStream_t stream);
......@@ -855,7 +855,7 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaSetDoubleForDevice(&val) );
cudaSafeCall( cudaSetDoubleForDevice(&scale) );
DivideScalar<T, D> op(val, scale);
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void divide_gpu<uchar, uchar >(const DevMem2Db& src1, double val, const DevMem2Db& dst, double scale, cudaStream_t stream);
......@@ -949,7 +949,7 @@ namespace cv { namespace gpu { namespace device
{
cudaSafeCall( cudaSetDoubleForDevice(&scalar) );
Reciprocal<T, D> op(scalar);
::cv::gpu::device::transform((DevMem2D_<T>)src2, (DevMem2D_<D>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src2, (DevMem2D_<D>)dst, op, WithOutMask(), stream);
}
template void divide_gpu<uchar, uchar >(double scalar, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1055,7 +1055,7 @@ namespace cv { namespace gpu { namespace device
template <typename T> void absdiff_gpu(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream)
{
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<T>)dst, Absdiff<T>(), stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)src2, (DevMem2D_<T>)dst, Absdiff<T>(), WithOutMask(), stream);
}
template void absdiff_gpu<uchar >(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1101,7 +1101,7 @@ namespace cv { namespace gpu { namespace device
{
cudaSafeCall( cudaSetDoubleForDevice(&val) );
AbsdiffScalar<T> op(val);
::cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)dst, op, stream);
cv::gpu::device::transform((DevMem2D_<T>)src1, (DevMem2D_<T>)dst, op, WithOutMask(), stream);
}
template void absdiff_gpu<uchar >(const DevMem2Db& src1, double src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1188,7 +1188,7 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Op, typename T> void compare(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream)
{
Op<T> op;
::cv::gpu::device::transform(static_cast< DevMem2D_<T> >(src1), static_cast< DevMem2D_<T> >(src2), dst, op, stream);
cv::gpu::device::transform(static_cast< DevMem2D_<T> >(src1), static_cast< DevMem2D_<T> >(src2), dst, op, WithOutMask(), stream);
}
template <typename T> void compare_eq(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream)
......@@ -1546,7 +1546,7 @@ namespace cv { namespace gpu { namespace device
template <typename T>
void min_gpu(const DevMem2D_<T>& src1, const DevMem2D_<T>& src2, const DevMem2D_<T>& dst, cudaStream_t stream)
{
::cv::gpu::device::transform(src1, src2, dst, minimum<T>(), stream);
cv::gpu::device::transform(src1, src2, dst, minimum<T>(), WithOutMask(), stream);
}
template void min_gpu<uchar >(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1560,7 +1560,7 @@ namespace cv { namespace gpu { namespace device
template <typename T>
void max_gpu(const DevMem2D_<T>& src1, const DevMem2D_<T>& src2, const DevMem2D_<T>& dst, cudaStream_t stream)
{
::cv::gpu::device::transform(src1, src2, dst, maximum<T>(), stream);
cv::gpu::device::transform(src1, src2, dst, maximum<T>(), WithOutMask(), stream);
}
template void max_gpu<uchar >(const DevMem2Db& src1, const DevMem2Db& src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1574,7 +1574,7 @@ namespace cv { namespace gpu { namespace device
template <typename T>
void min_gpu(const DevMem2D_<T>& src1, T src2, const DevMem2D_<T>& dst, cudaStream_t stream)
{
::cv::gpu::device::transform(src1, dst, device::bind2nd(minimum<T>(), src2), stream);
cv::gpu::device::transform(src1, dst, device::bind2nd(minimum<T>(), src2), WithOutMask(), stream);
}
template void min_gpu<uchar >(const DevMem2Db& src1, uchar src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1588,7 +1588,7 @@ namespace cv { namespace gpu { namespace device
template <typename T>
void max_gpu(const DevMem2D_<T>& src1, T src2, const DevMem2D_<T>& dst, cudaStream_t stream)
{
::cv::gpu::device::transform(src1, dst, device::bind2nd(maximum<T>(), src2), stream);
cv::gpu::device::transform(src1, dst, device::bind2nd(maximum<T>(), src2), WithOutMask(), stream);
}
template void max_gpu<uchar >(const DevMem2Db& src1, uchar src2, const DevMem2Db& dst, cudaStream_t stream);
......@@ -1635,19 +1635,17 @@ namespace cv { namespace gpu { namespace device
};
template <template <typename> class Op, typename T>
void threshold_caller(const DevMem2D_<T>& src, const DevMem2D_<T>& dst, T thresh, T maxVal,
cudaStream_t stream)
void threshold_caller(const DevMem2D_<T>& src, const DevMem2D_<T>& dst, T thresh, T maxVal, cudaStream_t stream)
{
Op<T> op(thresh, maxVal);
::cv::gpu::device::transform(src, dst, op, stream);
cv::gpu::device::transform(src, dst, op, WithOutMask(), stream);
}
template <typename T>
void threshold_gpu(const DevMem2Db& src, const DevMem2Db& dst, T thresh, T maxVal, int type,
cudaStream_t stream)
{
typedef void (*caller_t)(const DevMem2D_<T>& src, const DevMem2D_<T>& dst, T thresh, T maxVal,
cudaStream_t stream);
typedef void (*caller_t)(const DevMem2D_<T>& src, const DevMem2D_<T>& dst, T thresh, T maxVal, cudaStream_t stream);
static const caller_t callers[] =
{
......@@ -1737,7 +1735,7 @@ namespace cv { namespace gpu { namespace device
template<typename T>
void pow_caller(const DevMem2Db& src, float power, DevMem2Db dst, cudaStream_t stream)
{
::cv::gpu::device::transform((DevMem2D_<T>)src, (DevMem2D_<T>)dst, PowOp<T>(power), stream);
cv::gpu::device::transform((DevMem2D_<T>)src, (DevMem2D_<T>)dst, PowOp<T>(power), WithOutMask(), stream);
}
template void pow_caller<uchar>(const DevMem2Db& src, float power, DevMem2Db dst, cudaStream_t stream);
......@@ -1829,7 +1827,7 @@ namespace cv { namespace gpu { namespace device
AddWeighted<T1, T2, D> op(alpha, beta, gamma);
::cv::gpu::device::transform(static_cast< DevMem2D_<T1> >(src1), static_cast< DevMem2D_<T2> >(src2), static_cast< DevMem2D_<D> >(dst), op, stream);
cv::gpu::device::transform(static_cast< DevMem2D_<T1> >(src1), static_cast< DevMem2D_<T2> >(src2), static_cast< DevMem2D_<D> >(dst), op, WithOutMask(), stream);
}
template void addWeighted_gpu<uchar, uchar, uchar>(const DevMem2Db& src1, double alpha, const DevMem2Db& src2, double beta, double gamma, const DevMem2Db& dst, cudaStream_t stream);
......
......@@ -44,7 +44,6 @@
#include "opencv2/gpu/device/limits.hpp"
#include "opencv2/gpu/device/saturate_cast.hpp"
#include "opencv2/gpu/device/vec_math.hpp"
#include "opencv2/gpu/device/transform.hpp"
namespace cv { namespace gpu { namespace device
{
......
......@@ -67,7 +67,7 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Filter, template <typename> class B, typename T> struct RemapDispatcherStream
{
static void call(const DevMem2D_<T>& src, const DevMem2Df& mapx, const DevMem2Df& mapy, const DevMem2D_<T>& dst,
static void call(DevMem2D_<T> src, DevMem2Df mapx, DevMem2Df mapy, DevMem2D_<T> dst,
const float* borderValue, cudaStream_t stream, int)
{
typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type work_type;
......@@ -86,7 +86,8 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Filter, template <typename> class B, typename T> struct RemapDispatcherNonStream
{
static void call(const DevMem2D_<T>& src, const DevMem2Df& mapx, const DevMem2Df& mapy, const DevMem2D_<T>& dst, const float* borderValue, int)
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, DevMem2Df mapx, DevMem2Df mapy,
DevMem2D_<T> dst, const float* borderValue, int)
{
typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type work_type;
......@@ -110,20 +111,23 @@ namespace cv { namespace gpu { namespace device
{ \
typedef type elem_type; \
typedef int index_type; \
int xoff, yoff; \
tex_remap_ ## 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_remap_ ## type , x, y); \
return tex2D(tex_remap_ ## type , x + xoff, y + yoff); \
} \
}; \
template <template <typename> class Filter, template <typename> class B> struct RemapDispatcherNonStream<Filter, B, type> \
{ \
static void call(const DevMem2D_< type >& src, const DevMem2Df& mapx, const DevMem2Df& mapy, const DevMem2D_< type >& dst, const float* borderValue, int cc) \
static void call(DevMem2D_< type > src, DevMem2D_< type > srcWhole, int xoff, int yoff, DevMem2Df mapx, DevMem2Df mapy, \
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_remap_ ## type , src); \
tex_remap_ ## type ##_reader texSrc; \
bindTexture(&tex_remap_ ## type , srcWhole); \
tex_remap_ ## type ##_reader texSrc(xoff, yoff); \
B<work_type> brd(src.rows, src.cols, VecTraits<work_type>::make(borderValue)); \
BorderReader< tex_remap_ ## type ##_reader, B<work_type> > brdSrc(texSrc, brd); \
Filter< BorderReader< tex_remap_ ## type ##_reader, B<work_type> > > filter_src(brdSrc); \
......@@ -134,14 +138,25 @@ namespace cv { namespace gpu { namespace device
}; \
template <template <typename> class Filter> struct RemapDispatcherNonStream<Filter, BrdReplicate, type> \
{ \
static void call(const DevMem2D_< type >& src, const DevMem2Df& mapx, const DevMem2Df& mapy, const DevMem2D_< type >& dst, const float*, int) \
static void call(DevMem2D_< type > src, DevMem2D_< type > srcWhole, int xoff, int yoff, DevMem2Df mapx, DevMem2Df mapy, \
DevMem2D_< type > dst, const float*, int) \
{ \
dim3 block(32, 8); \
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); \
bindTexture(&tex_remap_ ## type , src); \
tex_remap_ ## type ##_reader texSrc; \
Filter< tex_remap_ ## type ##_reader > filter_src(texSrc); \
remap<<<grid, block>>>(filter_src, mapx, mapy, dst); \
bindTexture(&tex_remap_ ## type , srcWhole); \
tex_remap_ ## type ##_reader texSrc(xoff, yoff); \
if (srcWhole.cols == src.cols && srcWhole.rows == src.rows) \
{ \
Filter< tex_remap_ ## type ##_reader > filter_src(texSrc); \
remap<<<grid, block>>>(filter_src, mapx, mapy, dst); \
} \
else \
{ \
BrdReplicate<type> brd(src.rows, src.cols); \
BorderReader< tex_remap_ ## type ##_reader, BrdReplicate<type> > brdSrc(texSrc, brd); \
Filter< BorderReader< tex_remap_ ## type ##_reader, BrdReplicate<type> > > filter_src(brdSrc); \
remap<<<grid, block>>>(filter_src, mapx, mapy, dst); \
} \
cudaSafeCall( cudaGetLastError() ); \
cudaSafeCall( cudaDeviceSynchronize() ); \
} \
......@@ -175,21 +190,21 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Filter, template <typename> class B, typename T> struct RemapDispatcher
{
static void call(const DevMem2D_<T>& src, const DevMem2Df& mapx, const DevMem2Df& mapy, const DevMem2D_<T>& dst,
const float* borderValue, cudaStream_t stream, int cc)
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, DevMem2Df mapx, DevMem2Df mapy,
DevMem2D_<T> dst, const float* borderValue, cudaStream_t stream, int cc)
{
if (stream == 0)
RemapDispatcherNonStream<Filter, B, T>::call(src, mapx, mapy, dst, borderValue, cc);
RemapDispatcherNonStream<Filter, B, T>::call(src, srcWhole, xoff, yoff, mapx, mapy, dst, borderValue, cc);
else
RemapDispatcherStream<Filter, B, T>::call(src, mapx, mapy, dst, borderValue, stream, cc);
}
};
template <typename T> void remap_gpu(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation,
int borderMode, const float* borderValue, cudaStream_t stream, int cc)
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)
{
typedef void (*caller_t)(const DevMem2D_<T>& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2D_<T>& dst,
const float* borderValue, cudaStream_t stream, int cc);
typedef void (*caller_t)(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, DevMem2Df xmap, DevMem2Df ymap,
DevMem2D_<T> dst, const float* borderValue, cudaStream_t stream, int cc);
static const caller_t callers[3][5] =
{
......@@ -216,37 +231,38 @@ namespace cv { namespace gpu { namespace device
}
};
callers[interpolation][borderMode](static_cast< DevMem2D_<T> >(src), xmap, ymap, static_cast< DevMem2D_<T> >(dst), borderValue, stream, cc);
callers[interpolation][borderMode](static_cast< DevMem2D_<T> >(src), static_cast< DevMem2D_<T> >(srcWhole), xoff, yoff, xmap, ymap,
static_cast< DevMem2D_<T> >(dst), borderValue, stream, cc);
}
template void remap_gpu<uchar >(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<uchar2>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<uchar3>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<uchar4>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<schar>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<char2>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<char3>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<char4>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<ushort >(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<ushort2>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<ushort3>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<ushort4>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<short >(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<short2>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<short3>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<short4>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<int >(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<int2>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<int3>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<int4>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<float >(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
//template void remap_gpu<float2>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<float3>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<float4>(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream, int cc);
template void remap_gpu<uchar >(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);
//template void remap_gpu<uchar2>(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);
template void remap_gpu<uchar3>(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);
template void remap_gpu<uchar4>(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);
//template void remap_gpu<schar>(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);
//template void remap_gpu<char2>(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);
//template void remap_gpu<char3>(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);
//template void remap_gpu<char4>(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);
template void remap_gpu<ushort >(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);
//template void remap_gpu<ushort2>(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);
template void remap_gpu<ushort3>(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);
template void remap_gpu<ushort4>(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);
template void remap_gpu<short >(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);
//template void remap_gpu<short2>(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);
template void remap_gpu<short3>(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);
template void remap_gpu<short4>(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);
//template void remap_gpu<int >(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);
//template void remap_gpu<int2>(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);
//template void remap_gpu<int3>(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);
//template void remap_gpu<int4>(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);
template void remap_gpu<float >(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);
//template void remap_gpu<float2>(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);
template void remap_gpu<float3>(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);
template void remap_gpu<float4>(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);
} // namespace imgproc
}}} // namespace cv { namespace gpu { namespace device
......@@ -80,7 +80,7 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Filter, typename T> struct ResizeDispatcherStream
{
static void call(const DevMem2D_<T>& src, float fx, float fy, const DevMem2D_<T>& dst, cudaStream_t stream)
static void call(DevMem2D_<T> src, float fx, float fy, DevMem2D_<T> dst, cudaStream_t stream)
{
dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
......@@ -95,7 +95,7 @@ namespace cv { namespace gpu { namespace device
};
template <typename T> struct ResizeDispatcherStream<PointFilter, T>
{
static void call(const DevMem2D_<T>& src, float fx, float fy, const DevMem2D_<T>& dst, cudaStream_t stream)
static void call(DevMem2D_<T> src, float fx, float fy, DevMem2D_<T> dst, cudaStream_t stream)
{
dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
......@@ -110,7 +110,7 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Filter, typename T> struct ResizeDispatcherNonStream
{
static void call(const DevMem2D_<T>& src, float fx, float fy, const DevMem2D_<T>& dst)
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, float fx, float fy, DevMem2D_<T> dst)
{
dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
......@@ -127,7 +127,7 @@ namespace cv { namespace gpu { namespace device
};
template <typename T> struct ResizeDispatcherNonStream<PointFilter, T>
{
static void call(const DevMem2D_<T>& src, float fx, float fy, const DevMem2D_<T>& dst)
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, float fx, float fy, DevMem2D_<T> dst)
{
dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
......@@ -148,19 +148,21 @@ namespace cv { namespace gpu { namespace device
{ \
typedef type elem_type; \
typedef int index_type; \
int xoff, yoff; \
tex_resize_ ## 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_resize_ ## type , x, y); \
return tex2D(tex_resize_ ## type , x + xoff, y + yoff); \
} \
}; \
template <template <typename> class Filter> struct ResizeDispatcherNonStream<Filter, type> \
{ \
static void call(const DevMem2D_< type >& src, float fx, float fy, const DevMem2D_< type >& dst) \
static void call(DevMem2D_< type > src, DevMem2D_< type > srcWhole, int xoff, int yoff, float fx, float fy, DevMem2D_< type > dst) \
{ \
dim3 block(32, 8); \
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); \
bindTexture(&tex_resize_ ## type , src); \
tex_resize_ ## type ##_reader texSrc; \
bindTexture(&tex_resize_ ## type , srcWhole); \
tex_resize_ ## type ##_reader texSrc(xoff, yoff); \
Filter< tex_resize_ ## type ##_reader > filter_src(texSrc); \
resize<<<grid, block>>>(filter_src, fx, fy, dst); \
cudaSafeCall( cudaGetLastError() ); \
......@@ -169,12 +171,12 @@ namespace cv { namespace gpu { namespace device
}; \
template <> struct ResizeDispatcherNonStream<PointFilter, type> \
{ \
static void call(const DevMem2D_< type >& src, float fx, float fy, const DevMem2D_< type >& dst) \
static void call(DevMem2D_< type > src, DevMem2D_< type > srcWhole, int xoff, int yoff, float fx, float fy, DevMem2D_< type > dst) \
{ \
dim3 block(32, 8); \
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); \
bindTexture(&tex_resize_ ## type , src); \
tex_resize_ ## type ##_reader texSrc; \
bindTexture(&tex_resize_ ## type , srcWhole); \
tex_resize_ ## type ##_reader texSrc(xoff, yoff); \
resizeNN<<<grid, block>>>(texSrc, fx, fy, dst); \
cudaSafeCall( cudaGetLastError() ); \
cudaSafeCall( cudaDeviceSynchronize() ); \
......@@ -209,55 +211,57 @@ namespace cv { namespace gpu { namespace device
template <template <typename> class Filter, typename T> struct ResizeDispatcher
{
static void call(const DevMem2D_<T>& src, float fx, float fy, const DevMem2D_<T>& dst, cudaStream_t stream)
static void call(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, float fx, float fy, DevMem2D_<T> dst, cudaStream_t stream)
{
if (stream == 0)
ResizeDispatcherNonStream<Filter, T>::call(src, fx, fy, dst);
ResizeDispatcherNonStream<Filter, T>::call(src, srcWhole, xoff, yoff, fx, fy, dst);
else
ResizeDispatcherStream<Filter, T>::call(src, fx, fy, dst, stream);
}
};
template <typename T> void resize_gpu(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream)
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)
{
typedef void (*caller_t)(const DevMem2D_<T>& src, float fx, float fy, const DevMem2D_<T>& dst, cudaStream_t stream);
typedef void (*caller_t)(DevMem2D_<T> src, DevMem2D_<T> srcWhole, int xoff, int yoff, float fx, float fy, DevMem2D_<T> dst, cudaStream_t stream);
static const caller_t callers[3] =
{
ResizeDispatcher<PointFilter, T>::call, ResizeDispatcher<LinearFilter, T>::call, ResizeDispatcher<CubicFilter, T>::call
};
callers[interpolation](static_cast< DevMem2D_<T> >(src), fx, fy, static_cast< DevMem2D_<T> >(dst), stream);
callers[interpolation](static_cast< DevMem2D_<T> >(src), static_cast< DevMem2D_<T> >(srcWhole), xoff, yoff, fx, fy,
static_cast< DevMem2D_<T> >(dst), stream);
}
template void resize_gpu<uchar >(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<uchar2>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<uchar3>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<uchar4>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<schar>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char2>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char3>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char4>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort >(const DevMem2Db& src,float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<ushort2>(const DevMem2Db& src,float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort3>(const DevMem2Db& src,float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort4>(const DevMem2Db& src,float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short >(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<short2>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short3>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short4>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int >(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int2>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int3>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int4>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float >(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<float2>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float3>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float4>(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
template void resize_gpu<uchar >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<uchar2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<uchar3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<uchar4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<schar>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<ushort2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<short2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float >(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<float2>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float3>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float4>(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
} // namespace imgproc
}}} // namespace cv { namespace gpu { namespace device
......@@ -114,7 +114,7 @@ namespace cv { namespace gpu { namespace device
namespace imgproc
{
template <typename T>
void remap_gpu(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst,
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);
}
}}}
......@@ -123,8 +123,9 @@ void cv::gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const Gp
{
using namespace ::cv::gpu::device::imgproc;
typedef void (*caller_t)(const DevMem2Db& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2Db& dst, int interpolation,
typedef void (*caller_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 caller_t callers[6][4] =
{
{remap_gpu<uchar>, 0/*remap_gpu<uchar2>*/, remap_gpu<uchar3>, remap_gpu<uchar4>},
......@@ -154,8 +155,13 @@ void cv::gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const Gp
DeviceInfo info;
int cc = info.majorVersion() * 10 + info.minorVersion();
Size wholeSize;
Point ofs;
src.locateROI(wholeSize, ofs);
func(src, xmap, ymap, dst, interpolation, gpuBorderType, borderValueFloat.val, StreamAccessor::getStream(stream), cc);
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);
}
////////////////////////////////////////////////////////////////////////
......@@ -310,7 +316,8 @@ namespace cv { namespace gpu { namespace device
{
namespace imgproc
{
template <typename T> void resize_gpu(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
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);
}
}}}
......@@ -342,18 +349,25 @@ void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, doub
}
cudaStream_t stream = StreamAccessor::getStream(s);
Size wholeSize;
Point ofs;
src.locateROI(wholeSize, ofs);
if ((src.type() == CV_8UC1 || src.type() == CV_8UC4) && (interpolation == INTER_NEAREST || interpolation == INTER_LINEAR))
{
static const int npp_inter[] = {NPPI_INTER_NN, NPPI_INTER_LINEAR, NPPI_INTER_CUBIC, 0, NPPI_INTER_LANCZOS};
NppiSize srcsz;
srcsz.width = src.cols;
srcsz.height = src.rows;
srcsz.width = wholeSize.width;
srcsz.height = wholeSize.height;
NppiRect srcrect;
srcrect.x = srcrect.y = 0;
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;
......@@ -362,12 +376,12 @@ void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, doub
if (src.type() == CV_8UC1)
{
nppSafeCall( nppiResize_8u_C1R(src.ptr<Npp8u>(), srcsz, static_cast<int>(src.step), srcrect,
nppSafeCall( nppiResize_8u_C1R(src.datastart, srcsz, static_cast<int>(src.step), srcrect,
dst.ptr<Npp8u>(), static_cast<int>(dst.step), dstsz, fx, fy, npp_inter[interpolation]) );
}
else
{
nppSafeCall( nppiResize_8u_C4R(src.ptr<Npp8u>(), srcsz, static_cast<int>(src.step), srcrect,
nppSafeCall( nppiResize_8u_C4R(src.datastart, srcsz, static_cast<int>(src.step), srcrect,
dst.ptr<Npp8u>(), static_cast<int>(dst.step), dstsz, fx, fy, npp_inter[interpolation]) );
}
......@@ -378,7 +392,8 @@ void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, doub
{
using namespace ::cv::gpu::device::imgproc;
typedef void (*caller_t)(const DevMem2Db& src, float fx, float fy, const DevMem2Db& dst, int interpolation, cudaStream_t stream);
typedef void (*caller_t)(DevMem2Db src, DevMem2Db srcWhole, int xoff, int yoff, float fx, float fy, DevMem2Db dst, int interpolation, cudaStream_t stream);
static const caller_t callers[6][4] =
{
{resize_gpu<uchar>, 0/*resize_gpu<uchar2>*/, resize_gpu<uchar3>, resize_gpu<uchar4>},
......@@ -389,7 +404,8 @@ void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, doub
{resize_gpu<float>, 0/*resize_gpu<float2>*/, resize_gpu<float3>, resize_gpu<float4>}
};
callers[src.depth()][src.channels() - 1](src, static_cast<float>(fx), static_cast<float>(fy), dst, interpolation, stream);
callers[src.depth()][src.channels() - 1](src, DevMem2Db(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y,
static_cast<float>(fx), static_cast<float>(fy), dst, interpolation, stream);
}
}
......@@ -526,14 +542,21 @@ namespace
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC);
dst.create(dsize, src.type());
Size wholeSize;
Point ofs;
src.locateROI(wholeSize, ofs);
NppiSize srcsz;
srcsz.height = src.rows;
srcsz.width = src.cols;
srcsz.height = wholeSize.height;
srcsz.width = wholeSize.width;
NppiRect srcroi;
srcroi.x = srcroi.y = 0;
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;
......@@ -546,19 +569,19 @@ namespace
switch (src.depth())
{
case CV_8U:
nppSafeCall( npp_warp_8u[src.channels()][warpInd](src.ptr<Npp8u>(), srcsz, static_cast<int>(src.step), srcroi,
nppSafeCall( npp_warp_8u[src.channels()][warpInd]((Npp8u*)src.datastart, srcsz, static_cast<int>(src.step), srcroi,
dst.ptr<Npp8u>(), static_cast<int>(dst.step), dstroi, coeffs, npp_inter[interpolation]) );
break;
case CV_16U:
nppSafeCall( npp_warp_16u[src.channels()][warpInd](src.ptr<Npp16u>(), srcsz, static_cast<int>(src.step), srcroi,
nppSafeCall( npp_warp_16u[src.channels()][warpInd]((Npp16u*)src.datastart, srcsz, static_cast<int>(src.step), srcroi,
dst.ptr<Npp16u>(), static_cast<int>(dst.step), dstroi, coeffs, npp_inter[interpolation]) );
break;
case CV_32S:
nppSafeCall( npp_warp_32s[src.channels()][warpInd](src.ptr<Npp32s>(), srcsz, static_cast<int>(src.step), srcroi,
nppSafeCall( npp_warp_32s[src.channels()][warpInd]((Npp32s*)src.datastart, srcsz, static_cast<int>(src.step), srcroi,
dst.ptr<Npp32s>(), static_cast<int>(dst.step), dstroi, coeffs, npp_inter[interpolation]) );
break;
case CV_32F:
nppSafeCall( npp_warp_32f[src.channels()][warpInd](src.ptr<Npp32f>(), srcsz, static_cast<int>(src.step), srcroi,
nppSafeCall( npp_warp_32f[src.channels()][warpInd]((Npp32f*)src.datastart, srcsz, static_cast<int>(src.step), srcroi,
dst.ptr<Npp32f>(), static_cast<int>(dst.step), dstroi, coeffs, npp_inter[interpolation]) );
break;
default:
......
......@@ -386,20 +386,6 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaDeviceSynchronize() );
}
};
template <typename T, typename D, typename UnOp, typename Mask>
static inline void transform_caller(DevMem2D_<T> src, DevMem2D_<D> dst, UnOp op, Mask mask, cudaStream_t stream)
{
typedef TransformFunctorTraits<UnOp> ft;
TransformDispatcher<VecTraits<T>::cn == 1 && VecTraits<D>::cn == 1 && ft::smart_shift != 1>::call(src, dst, op, mask, stream);
}
template <typename T1, typename T2, typename D, typename BinOp, typename Mask>
static inline void transform_caller(DevMem2D_<T1> src1, DevMem2D_<T2> src2, DevMem2D_<D> dst, BinOp op, Mask mask, cudaStream_t stream)
{
typedef TransformFunctorTraits<BinOp> ft;
TransformDispatcher<VecTraits<T1>::cn == 1 && VecTraits<T2>::cn == 1 && VecTraits<D>::cn == 1 && ft::smart_shift != 1>::call(src1, src2, dst, op, mask, stream);
}
} // namespace transform_detail
}}} // namespace cv { namespace gpu { namespace device
......
......@@ -49,28 +49,18 @@
namespace cv { namespace gpu { namespace device
{
template <typename T, typename D, typename UnOp>
static inline void transform(DevMem2D_<T> src, DevMem2D_<D> dst, UnOp op, cudaStream_t stream = 0)
template <typename T, typename D, typename UnOp, typename Mask>
static inline void transform(DevMem2D_<T> src, DevMem2D_<D> dst, UnOp op, Mask mask, cudaStream_t stream)
{
transform_detail::transform_caller(src, dst, op, WithOutMask(), stream);
typedef TransformFunctorTraits<UnOp> ft;
transform_detail::TransformDispatcher<VecTraits<T>::cn == 1 && VecTraits<D>::cn == 1 && ft::smart_shift != 1>::call(src, dst, op, mask, stream);
}
template <typename T, typename D, typename UnOp>
static inline void transform(DevMem2D_<T> src, DevMem2D_<D> dst, PtrStepb mask, UnOp op, cudaStream_t stream = 0)
template <typename T1, typename T2, typename D, typename BinOp, typename Mask>
static inline void transform(DevMem2D_<T1> src1, DevMem2D_<T2> src2, DevMem2D_<D> dst, BinOp op, Mask mask, cudaStream_t stream)
{
transform_detail::transform_caller(src, dst, op, SingleMask(mask), stream);
}
template <typename T1, typename T2, typename D, typename BinOp>
static inline void transform(DevMem2D_<T1> src1, DevMem2D_<T2> src2, DevMem2D_<D> dst, BinOp op, cudaStream_t stream = 0)
{
transform_detail::transform_caller(src1, src2, dst, op, WithOutMask(), stream);
}
template <typename T1, typename T2, typename D, typename BinOp>
static inline void transform(DevMem2D_<T1> src1, DevMem2D_<T2> src2, DevMem2D_<D> dst, PtrStepb mask, BinOp op, cudaStream_t stream = 0)
{
transform_detail::transform_caller(src1, src2, dst, op, SingleMask(mask), stream);
typedef TransformFunctorTraits<BinOp> ft;
transform_detail::TransformDispatcher<VecTraits<T1>::cn == 1 && VecTraits<T2>::cn == 1 && VecTraits<D>::cn == 1 && ft::smart_shift != 1>::call(src1, src2, dst, op, mask, stream);
}
}}}
......
......@@ -69,7 +69,7 @@ namespace cv { namespace gpu { namespace device
struct SingleMask
{
explicit __host__ __device__ __forceinline__ SingleMask(const PtrStepb& mask_) : mask(mask_) {}
explicit __host__ __device__ __forceinline__ SingleMask(PtrStepb mask_) : mask(mask_) {}
__device__ __forceinline__ bool operator()(int y, int x) const
{
......@@ -79,6 +79,19 @@ namespace cv { namespace gpu { namespace device
PtrStepb mask;
};
struct SingleMaskChannels
{
__host__ __device__ __forceinline__ SingleMaskChannels(PtrStepb mask_, int channels_) : mask(mask_), channels(channels_) {}
__device__ __forceinline__ bool operator()(int y, int x) const
{
return mask.ptr(y)[x / channels] != 0;
}
PtrStepb mask;
int channels;
};
struct MaskCollection
{
explicit __host__ __device__ __forceinline__ MaskCollection(PtrStepb* maskCollection_) : maskCollection(maskCollection_) {}
......
此差异已折叠。
......@@ -43,10 +43,13 @@
#ifdef HAVE_CUDA
using namespace cvtest;
using namespace testing;
//////////////////////////////////////////////////////////////////////////
// BlockMatching
struct StereoBlockMatching : testing::TestWithParam<cv::gpu::DeviceInfo>
struct StereoBlockMatching : TestWithParam<cv::gpu::DeviceInfo>
{
cv::Mat img_l;
cv::Mat img_r;
......@@ -71,9 +74,7 @@ struct StereoBlockMatching : testing::TestWithParam<cv::gpu::DeviceInfo>
};
TEST_P(StereoBlockMatching, Regression)
{
PRINT_PARAM(devInfo);
{
cv::Mat disp;
ASSERT_NO_THROW(
......@@ -90,12 +91,12 @@ TEST_P(StereoBlockMatching, Regression)
EXPECT_MAT_NEAR(img_template, disp, 0.0);
}
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBlockMatching, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBlockMatching, ALL_DEVICES);
//////////////////////////////////////////////////////////////////////////
// BeliefPropagation
struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
struct StereoBeliefPropagation : TestWithParam<cv::gpu::DeviceInfo>
{
cv::Mat img_l;
cv::Mat img_r;
......@@ -121,8 +122,6 @@ struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoBeliefPropagation, Regression)
{
PRINT_PARAM(devInfo);
cv::Mat disp;
ASSERT_NO_THROW(
......@@ -139,12 +138,12 @@ TEST_P(StereoBeliefPropagation, Regression)
EXPECT_MAT_NEAR(img_template, disp, 0.0);
}
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBeliefPropagation, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBeliefPropagation, ALL_DEVICES);
//////////////////////////////////////////////////////////////////////////
// ConstantSpaceBP
struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
struct StereoConstantSpaceBP : TestWithParam<cv::gpu::DeviceInfo>
{
cv::Mat img_l;
cv::Mat img_r;
......@@ -174,8 +173,6 @@ struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoConstantSpaceBP, Regression)
{
PRINT_PARAM(devInfo);
cv::Mat disp;
ASSERT_NO_THROW(
......@@ -192,12 +189,12 @@ TEST_P(StereoConstantSpaceBP, Regression)
EXPECT_MAT_NEAR(img_template, disp, 1.0);
}
INSTANTIATE_TEST_CASE_P(Calib3D, StereoConstantSpaceBP, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Calib3D, StereoConstantSpaceBP, ALL_DEVICES);
///////////////////////////////////////////////////////////////////////////////////////////////////////
// projectPoints
struct ProjectPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
struct ProjectPoints : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -231,8 +228,6 @@ struct ProjectPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(ProjectPoints, Accuracy)
{
PRINT_PARAM(devInfo);
cv::Mat dst;
ASSERT_NO_THROW(
......@@ -257,12 +252,12 @@ TEST_P(ProjectPoints, Accuracy)
}
}
INSTANTIATE_TEST_CASE_P(Calib3D, ProjectPoints, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Calib3D, ProjectPoints, ALL_DEVICES);
///////////////////////////////////////////////////////////////////////////////////////////////////////
// transformPoints
struct TransformPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
struct TransformPoints : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -289,8 +284,6 @@ struct TransformPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(TransformPoints, Accuracy)
{
PRINT_PARAM(devInfo);
cv::Mat dst;
ASSERT_NO_THROW(
......@@ -318,12 +311,12 @@ TEST_P(TransformPoints, Accuracy)
}
}
INSTANTIATE_TEST_CASE_P(Calib3D, TransformPoints, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Calib3D, TransformPoints, ALL_DEVICES);
///////////////////////////////////////////////////////////////////////////////////////////////////////
// solvePnPRansac
struct SolvePnPRansac : testing::TestWithParam<cv::gpu::DeviceInfo>
struct SolvePnPRansac : TestWithParam<cv::gpu::DeviceInfo>
{
static const int num_points = 5000;
......@@ -360,8 +353,6 @@ struct SolvePnPRansac : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(SolvePnPRansac, Accuracy)
{
PRINT_PARAM(devInfo);
cv::Mat rvec, tvec;
std::vector<int> inliers;
......@@ -374,6 +365,6 @@ TEST_P(SolvePnPRansac, Accuracy)
ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3f);
}
INSTANTIATE_TEST_CASE_P(Calib3D, SolvePnPRansac, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Calib3D, SolvePnPRansac, ALL_DEVICES);
#endif // HAVE_CUDA
......@@ -43,17 +43,53 @@
#ifdef HAVE_CUDA
using namespace cvtest;
using namespace testing;
int getValidMatchesCount(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2, const std::vector<cv::DMatch>& matches)
{
int validCount = 0;
for (size_t i = 0; i < matches.size(); ++i)
{
const cv::DMatch& m = matches[i];
const cv::KeyPoint& p1 = keypoints1[m.queryIdx];
const cv::KeyPoint& p2 = keypoints2[m.trainIdx];
const float maxPtDif = 1.f;
const float maxSizeDif = 1.f;
const float maxAngleDif = 2.f;
const float maxResponseDif = 0.1f;
float dist = (float) cv::norm(p1.pt - p2.pt);
if (dist < maxPtDif &&
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id)
{
++validCount;
}
}
return validCount;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// SURF
struct SURF : testing::TestWithParam<cv::gpu::DeviceInfo>
struct SURF : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
cv::Mat image;
cv::Mat mask;
std::vector<cv::KeyPoint> keypoints_gold;
std::vector<float> descriptors_gold;
cv::gpu::DeviceInfo devInfo;
virtual void SetUp()
{
......@@ -67,15 +103,14 @@ struct SURF : testing::TestWithParam<cv::gpu::DeviceInfo>
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
cv::SURF fdetector_gold; fdetector_gold.extended = false;
cv::SURF fdetector_gold;
fdetector_gold.extended = false;
fdetector_gold(image, mask, keypoints_gold, descriptors_gold);
}
};
TEST_P(SURF, EmptyDataTest)
{
PRINT_PARAM(devInfo);
cv::gpu::SURF_GPU fdetector;
cv::gpu::GpuMat image;
......@@ -92,9 +127,6 @@ TEST_P(SURF, EmptyDataTest)
TEST_P(SURF, Accuracy)
{
PRINT_PARAM(devInfo);
// Compute keypoints.
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
......@@ -102,7 +134,7 @@ TEST_P(SURF, Accuracy)
cv::gpu::GpuMat dev_descriptors;
cv::gpu::SURF_GPU fdetector; fdetector.extended = false;
fdetector(cv::gpu::GpuMat(image), cv::gpu::GpuMat(mask), keypoints, dev_descriptors);
fdetector(loadMat(image), loadMat(mask), keypoints, dev_descriptors);
dev_descriptors.download(descriptors);
);
......@@ -112,45 +144,19 @@ TEST_P(SURF, Accuracy)
matcher.match(cv::Mat(static_cast<int>(keypoints_gold.size()), 64, CV_32FC1, &descriptors_gold[0]), descriptors, matches);
int validCount = 0;
for (size_t i = 0; i < matches.size(); ++i)
{
const cv::DMatch& m = matches[i];
int validCount = getValidMatchesCount(keypoints_gold, keypoints, matches);
const cv::KeyPoint& p1 = keypoints_gold[m.queryIdx];
const cv::KeyPoint& p2 = keypoints[m.trainIdx];
const float maxPtDif = 1.f;
const float maxSizeDif = 1.f;
const float maxAngleDif = 2.f;
const float maxResponseDif = 0.1f;
float dist = (float)cv::norm(p1.pt - p2.pt);
if (dist < maxPtDif &&
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id)
{
++validCount;
}
}
double validRatio = (double)validCount / matches.size();
double validRatio = (double) validCount / matches.size();
EXPECT_GT(validRatio, 0.5);
}
INSTANTIATE_TEST_CASE_P(Features2D, SURF, testing::ValuesIn(devices(cv::gpu::GLOBAL_ATOMICS)));
INSTANTIATE_TEST_CASE_P(Features2D, SURF, DEVICES(cv::gpu::GLOBAL_ATOMICS));
/////////////////////////////////////////////////////////////////////////////////////////////////
// BruteForceMatcher
static const char* dists[] = {"L1Dist", "L2Dist", "HammingDist"};
struct BruteForceMatcher : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, cv::gpu::BruteForceMatcher_GPU_base::DistType, int> >
PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, int)
{
static const int queryDescCount = 300; // must be even number because we split train data in some cases in two
static const int countFactor = 4; // do not change it
......@@ -163,9 +169,9 @@ struct BruteForceMatcher : testing::TestWithParam< std::tr1::tuple<cv::gpu::Devi
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
distType = std::tr1::get<1>(GetParam());
dim = std::tr1::get<2>(GetParam());
devInfo = GET_PARAM(0);
distType = (cv::gpu::BruteForceMatcher_GPU_base::DistType)(int)GET_PARAM(1);
dim = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -205,23 +211,14 @@ struct BruteForceMatcher : testing::TestWithParam< std::tr1::tuple<cv::gpu::Devi
}
};
const int BruteForceMatcher::queryDescCount;
const int BruteForceMatcher::countFactor;
TEST_P(BruteForceMatcher, Match)
{
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
std::vector<cv::DMatch> matches;
ASSERT_NO_THROW(
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
matcher.match(cv::gpu::GpuMat(query), cv::gpu::GpuMat(train), matches);
matcher.match(loadMat(query), loadMat(train), matches);
);
ASSERT_EQ(queryDescCount, matches.size());
......@@ -239,12 +236,6 @@ TEST_P(BruteForceMatcher, Match)
TEST_P(BruteForceMatcher, MatchAdd)
{
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
std::vector<cv::DMatch> matches;
bool isMaskSupported;
......@@ -298,19 +289,13 @@ TEST_P(BruteForceMatcher, MatchAdd)
TEST_P(BruteForceMatcher, KnnMatch2)
{
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
const int knn = 2;
std::vector< std::vector<cv::DMatch> > matches;
ASSERT_NO_THROW(
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
matcher.knnMatch(cv::gpu::GpuMat(query), cv::gpu::GpuMat(train), matches, knn);
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn);
);
ASSERT_EQ(queryDescCount, matches.size());
......@@ -338,19 +323,13 @@ TEST_P(BruteForceMatcher, KnnMatch2)
TEST_P(BruteForceMatcher, KnnMatch3)
{
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
const int knn = 3;
std::vector< std::vector<cv::DMatch> > matches;
ASSERT_NO_THROW(
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
matcher.knnMatch(cv::gpu::GpuMat(query), cv::gpu::GpuMat(train), matches, knn);
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn);
);
ASSERT_EQ(queryDescCount, matches.size());
......@@ -378,12 +357,6 @@ TEST_P(BruteForceMatcher, KnnMatch3)
TEST_P(BruteForceMatcher, KnnMatchAdd2)
{
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
const int knn = 2;
std::vector< std::vector<cv::DMatch> > matches;
......@@ -448,12 +421,6 @@ TEST_P(BruteForceMatcher, KnnMatchAdd2)
TEST_P(BruteForceMatcher, KnnMatchAdd3)
{
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
const int knn = 3;
std::vector< std::vector<cv::DMatch> > matches;
......@@ -521,12 +488,6 @@ TEST_P(BruteForceMatcher, RadiusMatch)
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS))
return;
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
const float radius = 1.f / countFactor;
std::vector< std::vector<cv::DMatch> > matches;
......@@ -534,7 +495,7 @@ TEST_P(BruteForceMatcher, RadiusMatch)
ASSERT_NO_THROW(
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
matcher.radiusMatch(cv::gpu::GpuMat(query), cv::gpu::GpuMat(train), matches, radius);
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius);
);
ASSERT_EQ(queryDescCount, matches.size());
......@@ -560,12 +521,6 @@ TEST_P(BruteForceMatcher, RadiusMatchAdd)
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS))
return;
const char* distStr = dists[distType];
PRINT_PARAM(devInfo);
PRINT_PARAM(distStr);
PRINT_PARAM(dim);
int n = 3;
const float radius = 1.f / countFactor * n;
......@@ -631,15 +586,15 @@ TEST_P(BruteForceMatcher, RadiusMatchAdd)
ASSERT_EQ(0, badCount);
}
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher, testing::Combine(
testing::ValuesIn(devices()),
testing::Values(cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist),
testing::Values(57, 64, 83, 128, 179, 256, 304)));
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher, Combine(
ALL_DEVICES,
Values(cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist),
Values(57, 64, 83, 128, 179, 256, 304)));
/////////////////////////////////////////////////////////////////////////////////////////////////
// FAST
struct FAST : testing::TestWithParam<cv::gpu::DeviceInfo>
struct FAST : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -659,7 +614,7 @@ struct FAST : testing::TestWithParam<cv::gpu::DeviceInfo>
ASSERT_FALSE(image.empty());
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
threshold = rng.uniform(15, 80);
threshold = 30;
cv::FAST(image, keypoints_gold, threshold);
}
......@@ -709,12 +664,12 @@ TEST_P(FAST, Accuracy)
}
}
INSTANTIATE_TEST_CASE_P(Features2D, FAST, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Features2D, FAST, DEVICES(cv::gpu::GLOBAL_ATOMICS));
/////////////////////////////////////////////////////////////////////////////////////////////////
// ORB
struct ORB : testing::TestWithParam<cv::gpu::DeviceInfo>
struct ORB : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -738,7 +693,7 @@ struct ORB : testing::TestWithParam<cv::gpu::DeviceInfo>
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
npoints = 4000;
npoints = 1000;
cv::ORB orbCPU(npoints);
......@@ -746,34 +701,6 @@ struct ORB : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
int getValidMatchesCount(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2, const std::vector<cv::DMatch>& matches)
{
int count = 0;
for (size_t i = 0; i < matches.size(); ++i)
{
const cv::DMatch& m = matches[i];
const cv::KeyPoint& kp1 = keypoints1[m.queryIdx];
const cv::KeyPoint& kp2 = keypoints2[m.trainIdx];
bool isEq =
fabs(kp1.pt.x - kp2.pt.x) <= 1 &&
fabs(kp1.pt.y - kp2.pt.y) <= 1 &&
//fabs(kp1.size - kp2.size) < 1 &&
//fabs(kp1.angle - kp2.angle) <= 1 &&
//fabs(kp1.response - kp2.response) < 1 &&
//kp1.octave == kp2.octave &&
//kp1.class_id == kp2.class_id
true;
if (isEq)
++count;
}
return count;
}
TEST_P(ORB, Accuracy)
{
std::vector<cv::KeyPoint> keypoints;
......@@ -794,11 +721,11 @@ TEST_P(ORB, Accuracy)
matcher.match(descriptors_gold, descriptors, matches);
int count = getValidMatchesCount(keypoints_gold, keypoints, matches);
double ratio = 100.0 * count / matches.size();
double ratio = (double) count / matches.size();
ASSERT_GE(ratio, 70.0);
ASSERT_GE(ratio, 0.65);
}
INSTANTIATE_TEST_CASE_P(Features2D, ORB, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Features2D, ORB, DEVICES(cv::gpu::GLOBAL_ATOMICS));
#endif // HAVE_CUDA
......@@ -43,6 +43,9 @@
#ifdef HAVE_CUDA
using namespace cvtest;
using namespace testing;
namespace
{
double checkNorm(const cv::Mat& m1, const cv::Mat& m2, const cv::Size& ksize)
......@@ -69,10 +72,11 @@ namespace
/////////////////////////////////////////////////////////////////////////////////////////////////
// blur
struct Blur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, cv::Size, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
cv::Size ksize;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -82,8 +86,9 @@ struct Blur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int,
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
ksize = cv::Size(std::tr1::get<1>(GetParam()), std::tr1::get<2>(GetParam()));
devInfo = GET_PARAM(0);
ksize = GET_PARAM(1);
useRoi = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -98,42 +103,51 @@ struct Blur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int,
}
};
TEST_P(Blur, Accuracy)
TEST_P(Blur, Rgba)
{
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::blur(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, ksize);
cv::gpu::blur(cv::gpu::GpuMat(img_gray), dev_dst_gray, ksize);
cv::gpu::blur(loadMat(img_rgba, useRoi), dev_dst_rgba, ksize);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, ksize, 1.0);
}
TEST_P(Blur, Gray)
{
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::blur(loadMat(img_gray, useRoi), dev_dst_gray, ksize);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, ksize, 1.0);
}
INSTANTIATE_TEST_CASE_P(Filter, Blur, testing::Combine(
testing::ValuesIn(devices()),
testing::Values(3, 5, 7),
testing::Values(3, 5, 7)));
INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine(
ALL_DEVICES,
Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)),
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// sobel
struct Sobel : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, std::pair<int, int> > >
PARAM_TEST_CASE(Sobel, cv::gpu::DeviceInfo, int, int, int, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
int ksize;
int dx, dy;
int dx;
int dy;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -143,10 +157,14 @@ struct Sobel : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int,
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
ksize = std::tr1::get<1>(GetParam());
std::pair<int, int> d = std::tr1::get<2>(GetParam());
dx = d.first; dy = d.second;
devInfo = GET_PARAM(0);
ksize = GET_PARAM(1);
dx = GET_PARAM(2);
dy = GET_PARAM(3);
useRoi = GET_PARAM(4);
if (dx == 0 && dy == 0)
return;
cv::gpu::setDevice(devInfo.deviceID());
......@@ -161,43 +179,58 @@ struct Sobel : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int,
}
};
TEST_P(Sobel, Accuracy)
TEST_P(Sobel, Rgba)
{
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
PRINT_PARAM(dx);
PRINT_PARAM(dy);
if (dx == 0 && dy == 0)
return;
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Sobel(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, -1, dx, dy, ksize);
cv::gpu::Sobel(cv::gpu::GpuMat(img_gray), dev_dst_gray, -1, dx, dy, ksize);
cv::gpu::Sobel(loadMat(img_rgba, useRoi), dev_dst_rgba, -1, dx, dy, ksize);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, ksize, 0.0);
}
TEST_P(Sobel, Gray)
{
if (dx == 0 && dy == 0)
return;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Sobel(loadMat(img_gray, useRoi), dev_dst_gray, -1, dx, dy, ksize);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, ksize, 0.0);
}
INSTANTIATE_TEST_CASE_P(Filter, Sobel, testing::Combine(
testing::ValuesIn(devices()),
testing::Values(3, 5, 7),
testing::Values(std::make_pair(1, 0), std::make_pair(0, 1), std::make_pair(1, 1), std::make_pair(2, 0), std::make_pair(2, 1), std::make_pair(0, 2), std::make_pair(1, 2), std::make_pair(2, 2))));
INSTANTIATE_TEST_CASE_P(Filter, Sobel, Combine(
ALL_DEVICES,
Values(3, 5, 7),
Values(0, 1, 2),
Values(0, 1, 2),
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// scharr
struct Scharr : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, std::pair<int, int> > >
PARAM_TEST_CASE(Scharr, cv::gpu::DeviceInfo, int, int, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
int dx, dy;
int dx;
int dy;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -207,9 +240,13 @@ struct Scharr : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, std
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
std::pair<int, int> d = std::tr1::get<1>(GetParam());
dx = d.first; dy = d.second;
devInfo = GET_PARAM(0);
dx = GET_PARAM(1);
dy = GET_PARAM(2);
useRoi = GET_PARAM(3);
if (dx + dy != 1)
return;
cv::gpu::setDevice(devInfo.deviceID());
......@@ -224,41 +261,56 @@ struct Scharr : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, std
}
};
TEST_P(Scharr, Accuracy)
TEST_P(Scharr, Rgba)
{
PRINT_PARAM(devInfo);
PRINT_PARAM(dx);
PRINT_PARAM(dy);
if (dx + dy != 1)
return;
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Scharr(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, -1, dx, dy);
cv::gpu::Scharr(cv::gpu::GpuMat(img_gray), dev_dst_gray, -1, dx, dy);
cv::gpu::Scharr(loadMat(img_rgba, useRoi), dev_dst_rgba, -1, dx, dy);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0);
}
TEST_P(Scharr, Gray)
{
if (dx + dy != 1)
return;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Scharr(loadMat(img_gray, useRoi), dev_dst_gray, -1, dx, dy);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0);
}
INSTANTIATE_TEST_CASE_P(Filter, Scharr, testing::Combine(
testing::ValuesIn(devices()),
testing::Values(std::make_pair(1, 0), std::make_pair(0, 1))));
INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine(
ALL_DEVICES,
Values(0, 1),
Values(0, 1),
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// gaussianBlur
struct GaussianBlur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
cv::Size ksize;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -270,8 +322,9 @@ struct GaussianBlur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInf
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
ksize = cv::Size(std::tr1::get<1>(GetParam()), std::tr1::get<2>(GetParam()));
devInfo = GET_PARAM(0);
ksize = GET_PARAM(1);
useRoi = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -291,43 +344,49 @@ struct GaussianBlur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInf
}
};
TEST_P(GaussianBlur, Accuracy)
TEST_P(GaussianBlur, Rgba)
{
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
PRINT_PARAM(sigma1);
PRINT_PARAM(sigma2);
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::GaussianBlur(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, ksize, sigma1, sigma2);
cv::gpu::GaussianBlur(cv::gpu::GpuMat(img_gray), dev_dst_gray, ksize, sigma1, sigma2);
cv::gpu::GaussianBlur(loadMat(img_rgba, useRoi), dev_dst_rgba, ksize, sigma1, sigma2);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, ksize, 3.0);
}
TEST_P(GaussianBlur, Gray)
{
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::GaussianBlur(loadMat(img_gray, useRoi), dev_dst_gray, ksize, sigma1, sigma2);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, ksize, 3.0);
}
INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, testing::Combine(
testing::ValuesIn(devices()),
testing::Values(3, 5, 7),
testing::Values(3, 5, 7)));
INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine(
ALL_DEVICES,
Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)),
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// laplacian
struct Laplacian : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, int, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
int ksize;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -337,8 +396,9 @@ struct Laplacian : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo,
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
ksize = std::tr1::get<1>(GetParam());
devInfo = GET_PARAM(0);
ksize = GET_PARAM(1);
useRoi = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -353,39 +413,48 @@ struct Laplacian : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo,
}
};
TEST_P(Laplacian, Accuracy)
TEST_P(Laplacian, Rgba)
{
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Laplacian(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, -1, ksize);
cv::gpu::Laplacian(cv::gpu::GpuMat(img_gray), dev_dst_gray, -1, ksize);
cv::gpu::Laplacian(loadMat(img_rgba, useRoi), dev_dst_rgba, -1, ksize);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0);
}
TEST_P(Laplacian, Gray)
{
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::Laplacian(loadMat(img_gray, useRoi), dev_dst_gray, -1, ksize);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0);
}
INSTANTIATE_TEST_CASE_P(Filter, Laplacian, testing::Combine(
testing::ValuesIn(devices()),
testing::Values(1, 3)));
INSTANTIATE_TEST_CASE_P(Filter, Laplacian, Combine(
ALL_DEVICES,
Values(1, 3),
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// erode
struct Erode : testing::TestWithParam<cv::gpu::DeviceInfo>
PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -397,7 +466,8 @@ struct Erode : testing::TestWithParam<cv::gpu::DeviceInfo>
virtual void SetUp()
{
devInfo = GetParam();
devInfo = GET_PARAM(0);
useRoi = GET_PARAM(1);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -414,36 +484,47 @@ struct Erode : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
TEST_P(Erode, Accuracy)
TEST_P(Erode, Rgba)
{
PRINT_PARAM(devInfo);
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::erode(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, kernel);
cv::gpu::erode(cv::gpu::GpuMat(img_gray), dev_dst_gray, kernel);
cv::gpu::erode(loadMat(img_rgba, useRoi), dev_dst_rgba, kernel);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0);
}
TEST_P(Erode, Gray)
{
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::erode(loadMat(img_gray, useRoi), dev_dst_gray, kernel);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0);
}
INSTANTIATE_TEST_CASE_P(Filter, Erode, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Filter, Erode, Combine(
ALL_DEVICES,
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// dilate
struct Dilate : testing::TestWithParam<cv::gpu::DeviceInfo>
PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -455,7 +536,8 @@ struct Dilate : testing::TestWithParam<cv::gpu::DeviceInfo>
virtual void SetUp()
{
devInfo = GetParam();
devInfo = GET_PARAM(0);
useRoi = GET_PARAM(1);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -472,40 +554,48 @@ struct Dilate : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
TEST_P(Dilate, Accuracy)
TEST_P(Dilate, Rgba)
{
PRINT_PARAM(devInfo);
cv::Mat dst_rgba;
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::dilate(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, kernel);
cv::gpu::dilate(cv::gpu::GpuMat(img_gray), dev_dst_gray, kernel);
cv::gpu::dilate(loadMat(img_rgba, useRoi), dev_dst_rgba, kernel);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 3, 0.0);
}
TEST_P(Dilate, Gray)
{
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::dilate(loadMat(img_gray, useRoi), dev_dst_gray, kernel);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 3, 0.0);
}
INSTANTIATE_TEST_CASE_P(Filter, Dilate, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Filter, Dilate, Combine(
ALL_DEVICES,
USE_ROI));
/////////////////////////////////////////////////////////////////////////////////////////////////
// morphEx
static const int morphOps[] = {cv::MORPH_OPEN, CV_MOP_CLOSE, CV_MOP_GRADIENT, CV_MOP_TOPHAT, CV_MOP_BLACKHAT};
static const char* morphOps_str[] = {"MORPH_OPEN", "MOP_CLOSE", "MOP_GRADIENT", "MOP_TOPHAT", "MOP_BLACKHAT"};
struct MorphEx : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, MorphOp, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
int morphOpsIdx;
int morphOp;
bool useRoi;
cv::Mat img_rgba;
cv::Mat img_gray;
......@@ -517,8 +607,9 @@ struct MorphEx : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, in
virtual void SetUp()
{
devInfo = std::tr1::get<0>(GetParam());
morphOpsIdx = std::tr1::get<1>(GetParam());
devInfo = GET_PARAM(0);
morphOp = GET_PARAM(1);
useRoi = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -530,38 +621,44 @@ struct MorphEx : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, in
kernel = cv::Mat::ones(3, 3, CV_8U);
cv::morphologyEx(img_rgba, dst_gold_rgba, morphOps[morphOpsIdx], kernel);
cv::morphologyEx(img_gray, dst_gold_gray, morphOps[morphOpsIdx], kernel);
cv::morphologyEx(img_rgba, dst_gold_rgba, morphOp, kernel);
cv::morphologyEx(img_gray, dst_gold_gray, morphOp, kernel);
}
};
TEST_P(MorphEx, Accuracy)
TEST_P(MorphEx, Rgba)
{
const char* morphOpStr = morphOps_str[morphOpsIdx];
cv::Mat dst_rgba;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
PRINT_PARAM(devInfo);
PRINT_PARAM(morphOpStr);
cv::gpu::morphologyEx(loadMat(img_rgba, useRoi), dev_dst_rgba, morphOp, kernel);
cv::Mat dst_rgba;
dev_dst_rgba.download(dst_rgba);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 4, 0.0);
}
TEST_P(MorphEx, Gray)
{
cv::Mat dst_gray;
ASSERT_NO_THROW(
cv::gpu::GpuMat dev_dst_rgba;
cv::gpu::GpuMat dev_dst_gray;
cv::gpu::morphologyEx(cv::gpu::GpuMat(img_rgba), dev_dst_rgba, morphOps[morphOpsIdx], kernel);
cv::gpu::morphologyEx(cv::gpu::GpuMat(img_gray), dev_dst_gray, morphOps[morphOpsIdx], kernel);
cv::gpu::morphologyEx(loadMat(img_gray, useRoi), dev_dst_gray, morphOp, kernel);
dev_dst_rgba.download(dst_rgba);
dev_dst_gray.download(dst_gray);
);
EXPECT_MAT_NEAR_KSIZE(dst_gold_rgba, dst_rgba, 4, 0.0);
EXPECT_MAT_NEAR_KSIZE(dst_gold_gray, dst_gray, 4, 0.0);
}
INSTANTIATE_TEST_CASE_P(Filter, MorphEx, testing::Combine(
testing::ValuesIn(devices()),
testing::Range(0, 5)));
INSTANTIATE_TEST_CASE_P(Filter, MorphEx, Combine(
ALL_DEVICES,
Values((int)cv::MORPH_OPEN, (int)cv::MORPH_CLOSE, (int)cv::MORPH_GRADIENT, (int)cv::MORPH_TOPHAT, (int)cv::MORPH_BLACKHAT),
USE_ROI));
#endif // HAVE_CUDA
......@@ -41,25 +41,53 @@
#include "test_precomp.hpp"
bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature)
using namespace std;
using namespace cv;
using namespace cv::gpu;
using namespace cvtest;
GpuMat loadMat(const Mat& m, bool useRoi)
{
Size size = m.size();
Size size0 = size;
if (useRoi)
{
RNG& rng = TS::ptr()->get_rng();
size0.width += rng.uniform(5, 15);
size0.height += rng.uniform(5, 15);
}
GpuMat d_m(size0, m.type());
if (size0 != size)
d_m = d_m(Rect((size0.width - size.width) / 2, (size0.height - size.height) / 2, size.width, size.height));
d_m.upload(m);
return d_m;
}
bool supportFeature(const DeviceInfo& info, FeatureSet feature)
{
return cv::gpu::TargetArchs::builtWith(feature) && info.supports(feature);
return TargetArchs::builtWith(feature) && info.supports(feature);
}
const std::vector<cv::gpu::DeviceInfo>& devices()
const vector<DeviceInfo>& devices()
{
static std::vector<cv::gpu::DeviceInfo> devs;
static vector<DeviceInfo> devs;
static bool first = true;
if (first)
{
int deviceCount = cv::gpu::getCudaEnabledDeviceCount();
int deviceCount = getCudaEnabledDeviceCount();
devs.reserve(deviceCount);
for (int i = 0; i < deviceCount; ++i)
{
cv::gpu::DeviceInfo info(i);
DeviceInfo info(i);
if (info.isCompatible())
devs.push_back(info);
}
......@@ -70,19 +98,19 @@ const std::vector<cv::gpu::DeviceInfo>& devices()
return devs;
}
std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature)
vector<DeviceInfo> devices(FeatureSet feature)
{
const std::vector<cv::gpu::DeviceInfo>& d = devices();
const vector<DeviceInfo>& d = devices();
std::vector<cv::gpu::DeviceInfo> devs_filtered;
vector<DeviceInfo> devs_filtered;
if (cv::gpu::TargetArchs::builtWith(feature))
if (TargetArchs::builtWith(feature))
{
devs_filtered.reserve(d.size());
for (size_t i = 0, size = d.size(); i < size; ++i)
{
const cv::gpu::DeviceInfo& info = d[i];
const DeviceInfo& info = d[i];
if (info.supports(feature))
devs_filtered.push_back(info);
......@@ -92,9 +120,9 @@ std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature)
return devs_filtered;
}
std::vector<int> types(int depth_start, int depth_end, int cn_start, int cn_end)
vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
{
std::vector<int> v;
vector<MatType> v;
v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
......@@ -109,46 +137,39 @@ std::vector<int> types(int depth_start, int depth_end, int cn_start, int cn_end)
return v;
}
const std::vector<int>& all_types()
const vector<MatType>& all_types()
{
static std::vector<int> v = types(CV_8U, CV_64F, 1, 4);
static vector<MatType> v = types(CV_8U, CV_64F, 1, 4);
return v;
}
cv::Mat readImage(const std::string& fileName, int flags)
Mat readImage(const string& fileName, int flags)
{
return cv::imread(std::string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
}
double checkNorm(const cv::Mat& m1, const cv::Mat& m2)
double checkNorm(const Mat& m1, const Mat& m2)
{
return cv::norm(m1, m2, cv::NORM_INF);
return norm(m1, m2, NORM_INF);
}
double checkSimilarity(const cv::Mat& m1, const cv::Mat& m2)
double checkSimilarity(const Mat& m1, const Mat& m2)
{
cv::Mat diff;
cv::matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
Mat diff;
matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
return std::abs(diff.at<float>(0, 0) - 1.f);
}
namespace cv
void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os)
{
std::ostream& operator << (std::ostream& os, const Size& sz)
{
return os << sz.width << "x" << sz.height;
}
std::ostream& operator << (std::ostream& os, const Scalar& s)
{
return os << "[" << s[0] << ", " << s[1] << ", " << s[2] << ", " << s[3] << "]";
}
(*os) << info.name();
}
namespace gpu
{
std::ostream& operator << (std::ostream& os, const DeviceInfo& info)
{
return os << info.name();
}
}
void PrintTo(const UseRoi& useRoi, std::ostream* os)
{
if (useRoi)
(*os) << "sub matrix";
else
(*os) << "whole matrix";
}
......@@ -42,6 +42,8 @@
#ifndef __OPENCV_TEST_GPU_BASE_HPP__
#define __OPENCV_TEST_GPU_BASE_HPP__
cv::gpu::GpuMat loadMat(const cv::Mat& m, bool useRoi = false);
//! return true if device supports specified feature and gpu module was built with support the feature.
bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
......@@ -50,30 +52,12 @@ const std::vector<cv::gpu::DeviceInfo>& devices();
//! return all devices compatible with current gpu module build which support specified feature.
std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature);
//! return vector with types from specified range.
std::vector<int> types(int depth_start, int depth_end, int cn_start, int cn_end);
//! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
const std::vector<int>& all_types();
//! read image from testdata folder.
cv::Mat readImage(const std::string& fileName, int flags = CV_LOAD_IMAGE_COLOR);
cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
double checkNorm(const cv::Mat& m1, const cv::Mat& m2);
double checkSimilarity(const cv::Mat& m1, const cv::Mat& m2);
#define OSTR_NAME(suf) ostr_ ## suf
#define PRINT_PARAM(name) \
std::ostringstream OSTR_NAME(name); \
OSTR_NAME(name) << # name << ": " << name; \
SCOPED_TRACE(OSTR_NAME(name).str());
#define PRINT_TYPE(type) \
std::ostringstream OSTR_NAME(type); \
OSTR_NAME(type) << # type << ": " << cvtest::getTypeName(type) << "c" << CV_MAT_CN(type); \
SCOPED_TRACE(OSTR_NAME(type).str());
#define EXPECT_MAT_NEAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
......@@ -88,16 +72,66 @@ double checkSimilarity(const cv::Mat& m1, const cv::Mat& m2);
EXPECT_LE(checkSimilarity(mat1, mat2), eps); \
}
namespace cv { namespace gpu
{
void PrintTo(const DeviceInfo& info, std::ostream* os);
}}
using perf::MatDepth;
using perf::MatType;
//! return vector with types from specified range.
std::vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end);
//! for gtest ASSERT
namespace cv
//! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
const std::vector<MatType>& all_types();
class UseRoi
{
std::ostream& operator << (std::ostream& os, const Size& sz);
std::ostream& operator << (std::ostream& os, const Scalar& s);
namespace gpu
{
std::ostream& operator << (std::ostream& os, const DeviceInfo& info);
}
}
public:
inline UseRoi(bool val = false) : val_(val) {}
inline operator bool() const { return val_; }
private:
bool val_;
};
void PrintTo(const UseRoi& useRoi, std::ostream* os);
CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE)
CV_ENUM(NormCode, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_TYPE_MASK, cv::NORM_RELATIVE, cv::NORM_MINMAX)
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
CV_ENUM(ReduceOp, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN)
CV_FLAGS(GemmFlags, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T);
CV_ENUM(DistType, cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist)
CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT)
CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV)
CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC)
CV_ENUM(Border, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP)
CV_FLAGS(WarpFlags, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::WARP_INVERSE_MAP)
CV_ENUM(TemplateMethod, cv::TM_SQDIFF, cv::TM_SQDIFF_NORMED, cv::TM_CCORR, cv::TM_CCORR_NORMED, cv::TM_CCOEFF, cv::TM_CCOEFF_NORMED)
CV_FLAGS(DftFlags, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
#define ALL_DEVICES testing::ValuesIn(devices())
#define DEVICES(feature) testing::ValuesIn(devices(feature))
#define ALL_TYPES testing::ValuesIn(all_types())
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
#define USE_ROI testing::Values(false, true)
#endif // __OPENCV_TEST_GPU_BASE_HPP__
......@@ -43,6 +43,9 @@
#ifdef HAVE_CUDA
using namespace cvtest;
using namespace testing;
//#define DUMP
struct CV_GpuHogDetectTestRunner : cv::gpu::HOGDescriptor
......@@ -169,7 +172,7 @@ struct CV_GpuHogDetectTestRunner : cv::gpu::HOGDescriptor
#endif
};
struct HogDetect : testing::TestWithParam<cv::gpu::DeviceInfo>
struct Detect : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -181,17 +184,15 @@ struct HogDetect : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
TEST_P(HogDetect, Accuracy)
TEST_P(Detect, Accuracy)
{
PRINT_PARAM(devInfo);
ASSERT_NO_THROW(
CV_GpuHogDetectTestRunner runner;
runner.run();
);
}
INSTANTIATE_TEST_CASE_P(HOG, HogDetect, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(HOG, Detect, ALL_DEVICES);
struct CV_GpuHogGetDescriptorsTestRunner : cv::gpu::HOGDescriptor
{
......@@ -301,7 +302,7 @@ struct CV_GpuHogGetDescriptorsTestRunner : cv::gpu::HOGDescriptor
int block_hist_size;
};
struct HogGetDescriptors : testing::TestWithParam<cv::gpu::DeviceInfo>
struct GetDescriptors : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -313,16 +314,14 @@ struct HogGetDescriptors : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
TEST_P(HogGetDescriptors, Accuracy)
TEST_P(GetDescriptors, Accuracy)
{
PRINT_PARAM(devInfo);
ASSERT_NO_THROW(
CV_GpuHogGetDescriptorsTestRunner runner;
runner.run();
);
}
INSTANTIATE_TEST_CASE_P(HOG, HogGetDescriptors, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(HOG, GetDescriptors, ALL_DEVICES);
#endif // HAVE_CUDA
此差异已折叠。
......@@ -42,8 +42,15 @@
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
#include <cuda_runtime_api.h>
using namespace std;
using namespace cv;
using namespace cv::gpu;
using namespace cvtest;
using namespace testing;
void print_info()
{
printf("\n");
......@@ -67,18 +74,18 @@ void print_info()
# endif
#endif
int deviceCount = cv::gpu::getCudaEnabledDeviceCount();
int deviceCount = getCudaEnabledDeviceCount();
int driver;
cudaDriverGetVersion(&driver);
printf("CUDA Driver version: %d\n", driver);
printf("CUDA Runtime version: %d\n", CUDART_VERSION);
printf("CUDA device count: %d\n\n", deviceCount);
printf("CUDA device count: %d\n\n", deviceCount);
for (int i = 0; i < deviceCount; ++i)
{
cv::gpu::DeviceInfo info(i);
DeviceInfo info(i);
printf("Device %d:\n", i);
printf(" Name: %s\n", info.name().c_str());
printf(" Compute capability version: %d.%d\n", info.majorVersion(), info.minorVersion());
......@@ -106,14 +113,14 @@ extern OutputLevel nvidiaTestOutputLevel;
int main(int argc, char** argv)
{
cvtest::TS::ptr()->init("gpu");
testing::InitGoogleTest(&argc, argv);
TS::ptr()->init("gpu");
InitGoogleTest(&argc, argv);
const char* keys ="{ nvtest_output_level | nvtest_output_level | none | NVidia test verbosity level }";
cv::CommandLineParser parser(argc, (const char**)argv, keys);
CommandLineParser parser(argc, (const char**)argv, keys);
std::string outputLevel = parser.get<std::string>("nvtest_output_level", "none");
string outputLevel = parser.get<string>("nvtest_output_level", "none");
if (outputLevel == "none")
nvidiaTestOutputLevel = OutputLevelNone;
......@@ -123,6 +130,7 @@ int main(int argc, char** argv)
nvidiaTestOutputLevel = OutputLevelFull;
print_info();
return RUN_ALL_TESTS();
}
......
此差异已折叠。
......@@ -43,6 +43,9 @@
#ifdef HAVE_CUDA
using namespace cvtest;
using namespace testing;
enum OutputLevel
{
OutputLevelNone,
......@@ -62,27 +65,22 @@ bool nvidia_NCV_Haar_Cascade_Application(const std::string& test_data_path, Outp
bool nvidia_NCV_Hypotheses_Filtration(const std::string& test_data_path, OutputLevel outputLevel);
bool nvidia_NCV_Visualization(const std::string& test_data_path, OutputLevel outputLevel);
struct NVidiaTest : testing::TestWithParam<cv::gpu::DeviceInfo>
struct NVidiaTest : TestWithParam<cv::gpu::DeviceInfo>
{
static std::string path;
cv::gpu::DeviceInfo devInfo;
static void SetUpTestCase()
{
path = std::string(cvtest::TS::ptr()->get_data_path()) + "haarcascade/";
}
std::string path;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
path = std::string(TS::ptr()->get_data_path()) + "haarcascade/";
}
};
std::string NVidiaTest::path;
struct NPPST : NVidiaTest {};
struct NCV : NVidiaTest {};
......@@ -90,8 +88,6 @@ OutputLevel nvidiaTestOutputLevel = OutputLevelNone;
TEST_P(NPPST, Integral)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -103,8 +99,6 @@ TEST_P(NPPST, Integral)
TEST_P(NPPST, SquaredIntegral)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -116,8 +110,6 @@ TEST_P(NPPST, SquaredIntegral)
TEST_P(NPPST, RectStdDev)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -129,8 +121,6 @@ TEST_P(NPPST, RectStdDev)
TEST_P(NPPST, Resize)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -142,8 +132,6 @@ TEST_P(NPPST, Resize)
TEST_P(NPPST, VectorOperations)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -155,8 +143,6 @@ TEST_P(NPPST, VectorOperations)
TEST_P(NPPST, Transpose)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -168,8 +154,6 @@ TEST_P(NPPST, Transpose)
TEST_P(NCV, VectorOperations)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -181,8 +165,6 @@ TEST_P(NCV, VectorOperations)
TEST_P(NCV, HaarCascadeLoader)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -194,8 +176,6 @@ TEST_P(NCV, HaarCascadeLoader)
TEST_P(NCV, HaarCascadeApplication)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -207,8 +187,6 @@ TEST_P(NCV, HaarCascadeApplication)
TEST_P(NCV, HypothesesFiltration)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -220,8 +198,6 @@ TEST_P(NCV, HypothesesFiltration)
TEST_P(NCV, Visualization)
{
PRINT_PARAM(devInfo);
bool res;
ASSERT_NO_THROW(
......@@ -231,7 +207,7 @@ TEST_P(NCV, Visualization)
ASSERT_TRUE(res);
}
INSTANTIATE_TEST_CASE_P(NVidia, NPPST, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(NVidia, NCV, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(NVidia, NPPST, ALL_DEVICES);
INSTANTIATE_TEST_CASE_P(NVidia, NCV, ALL_DEVICES);
#endif // HAVE_CUDA
......@@ -56,6 +56,7 @@
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "test_gpu_base.hpp"
......
......@@ -43,6 +43,9 @@
#ifdef HAVE_CUDA
using namespace cvtest;
using namespace testing;
//#define DUMP
#define OPTICAL_FLOW_DUMP_FILE "opticalflow/opticalflow_gold.bin"
......@@ -50,7 +53,10 @@
#define INTERPOLATE_FRAMES_DUMP_FILE "opticalflow/interpolate_frames_gold.bin"
#define INTERPOLATE_FRAMES_DUMP_FILE_CC20 "opticalflow/interpolate_frames_gold_cc20.bin"
struct BroxOpticalFlow : testing::TestWithParam< cv::gpu::DeviceInfo >
/////////////////////////////////////////////////////////////////////////////////////////////////
// BroxOpticalFlow
struct BroxOpticalFlow : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -105,8 +111,6 @@ struct BroxOpticalFlow : testing::TestWithParam< cv::gpu::DeviceInfo >
TEST_P(BroxOpticalFlow, Regression)
{
PRINT_PARAM(devInfo);
cv::Mat u;
cv::Mat v;
......@@ -149,9 +153,12 @@ TEST_P(BroxOpticalFlow, Regression)
#endif
}
INSTANTIATE_TEST_CASE_P(Video, BroxOpticalFlow, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Video, BroxOpticalFlow, ALL_DEVICES);
struct InterpolateFrames : testing::TestWithParam< cv::gpu::DeviceInfo >
/////////////////////////////////////////////////////////////////////////////////////////////////
// InterpolateFrames
struct InterpolateFrames : TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
......@@ -200,8 +207,6 @@ struct InterpolateFrames : testing::TestWithParam< cv::gpu::DeviceInfo >
TEST_P(InterpolateFrames, Regression)
{
PRINT_PARAM(devInfo);
cv::Mat newFrame;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
......@@ -246,6 +251,6 @@ TEST_P(InterpolateFrames, Regression)
#endif
}
INSTANTIATE_TEST_CASE_P(Video, InterpolateFrames, testing::ValuesIn(devices()));
INSTANTIATE_TEST_CASE_P(Video, InterpolateFrames, ALL_DEVICES);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册