diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index c3ba8c6d64..0d510b8ade 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -929,12 +929,9 @@ static bool ocl_binary_op(InputArray _src1, InputArray _src2, OutputArray _dst, int srcdepth = CV_MAT_DEPTH(srctype); int cn = CV_MAT_CN(srctype); - if( oclop < 0 || ((haveMask || haveScalar) && cn > 4) ) + if( oclop < 0 || ((haveMask || haveScalar) && cn > 4) || cn == 3) return false; - UMat src1 = _src1.getUMat(), src2; - UMat dst = _dst.getUMat(), mask = _mask.getUMat(); - char opts[1024]; int kercn = haveMask || haveScalar ? cn : 1; sprintf(opts, "-D %s%s -D %s -D dstT=%s", @@ -946,6 +943,9 @@ static bool ocl_binary_op(InputArray _src1, InputArray _src2, OutputArray _dst, if( k.empty() ) return false; + UMat src1 = _src1.getUMat(), src2; + UMat dst = _dst.getUMat(), mask = _mask.getUMat(); + int cscale = cn/kercn; ocl::KernelArg src1arg = ocl::KernelArg::ReadOnlyNoSize(src1, cscale); ocl::KernelArg dstarg = haveMask ? ocl::KernelArg::ReadWrite(dst, cscale) : @@ -1280,24 +1280,28 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, void* usrdata, int oclop, bool haveScalar ) { + bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; int type1 = _src1.type(), depth1 = CV_MAT_DEPTH(type1), cn = CV_MAT_CN(type1); bool haveMask = !_mask.empty(); - if( ((haveMask || haveScalar) && cn > 4) || cn == 3) // TODO need fix for 3 channels + if( ((haveMask || haveScalar) && cn > 4) || cn == 3) return false; int dtype = _dst.type(), ddepth = CV_MAT_DEPTH(dtype), wdepth = std::max(CV_32S, CV_MAT_DEPTH(wtype)); + if (!doubleSupport) + wdepth = std::min(wdepth, CV_32F); + wtype = CV_MAKETYPE(wdepth, cn); int type2 = haveScalar ? wtype : _src2.type(), depth2 = CV_MAT_DEPTH(type2); - int kercn = haveMask || haveScalar ? cn : 1; + if (!doubleSupport && (depth2 == CV_64F || depth1 == CV_64F)) + return false; - UMat src1 = _src1.getUMat(), src2; - UMat dst = _dst.getUMat(), mask = _mask.getUMat(); + int kercn = haveMask || haveScalar ? cn : 1; char cvtstr[3][32], opts[1024]; sprintf(opts, "-D %s%s -D %s -D srcT1=%s -D srcT2=%s " "-D dstT=%s -D workT=%s -D convertToWT1=%s " - "-D convertToWT2=%s -D convertToDT=%s", + "-D convertToWT2=%s -D convertToDT=%s%s", (haveMask ? "MASK_" : ""), (haveScalar ? "UNARY_OP" : "BINARY_OP"), oclop2str[oclop], ocl::typeToStr(CV_MAKETYPE(depth1, kercn)), ocl::typeToStr(CV_MAKETYPE(depth2, kercn)), @@ -1305,7 +1309,8 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, ocl::typeToStr(CV_MAKETYPE(wdepth, kercn)), ocl::convertTypeStr(depth1, wdepth, kercn, cvtstr[0]), ocl::convertTypeStr(depth2, wdepth, kercn, cvtstr[1]), - ocl::convertTypeStr(wdepth, ddepth, kercn, cvtstr[2])); + ocl::convertTypeStr(wdepth, ddepth, kercn, cvtstr[2]), + doubleSupport ? " -D DOUBLE_SUPPORT" : ""); const uchar* usrdata_p = (const uchar*)usrdata; const double* usrdata_d = (const double*)usrdata; @@ -1323,6 +1328,9 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, if( k.empty() ) return false; + UMat src1 = _src1.getUMat(), src2; + UMat dst = _dst.getUMat(), mask = _mask.getUMat(); + int cscale = cn/kercn; ocl::KernelArg src1arg = ocl::KernelArg::ReadOnlyNoSize(src1, cscale); @@ -1337,9 +1345,7 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, Mat src2sc = _src2.getMat(); if( !src2sc.empty() ) - { convertAndUnrollScalar(src2sc, wtype, (uchar*)buf, 1); - } ocl::KernelArg scalararg = ocl::KernelArg(0, 0, 0, buf, esz); if( !haveMask ) @@ -1369,12 +1375,10 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, CV_Error(Error::StsNotImplemented, "unsupported number of extra parameters"); } else - { k.args(src1arg, src2arg, maskarg, dstarg); - } } - size_t globalsize[] = { src1.cols*cscale, src1.rows }; + size_t globalsize[] = { src1.cols * cscale, src1.rows }; return k.run(2, globalsize, NULL, false); } @@ -2075,7 +2079,7 @@ void cv::multiply(InputArray src1, InputArray src2, OutputArray dst, double scale, int dtype) { arithm_op(src1, src2, dst, noArray(), dtype, getMulTab(), - true, &scale, scale == 1. ? OCL_OP_MUL : OCL_OP_MUL_SCALE); + true, &scale, std::abs(scale - 1.0) < DBL_EPSILON ? OCL_OP_MUL : OCL_OP_MUL_SCALE); } void cv::divide(InputArray src1, InputArray src2, diff --git a/modules/core/src/opencl/arithm.cl b/modules/core/src/opencl/arithm.cl index a9c23645ac..87a9dece66 100644 --- a/modules/core/src/opencl/arithm.cl +++ b/modules/core/src/opencl/arithm.cl @@ -57,7 +57,7 @@ -D workDepth= [-D cn=]" - for mixed-type operations */ -#if defined (DOUBLE_SUPPORT) +#ifdef DOUBLE_SUPPORT #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64:enable #elif defined (cl_amd_fp64) @@ -69,7 +69,7 @@ #define CV_32F 5 #define dstelem *(__global dstT*)(dstptr + dst_index) -#define noconvert(x) x +#define noconvert #ifndef workT @@ -99,7 +99,9 @@ #define PROCESS_ELEM dstelem = convertToDT(srcelem2 - srcelem1) #elif defined OP_ABSDIFF -#define PROCESS_ELEM dstelem = abs_diff(srcelem1, srcelem2) +#define PROCESS_ELEM \ + workT v = srcelem1 - srcelem2; \ + dstelem = convertToDT(v >= (workT)(0) ? v : -v); #elif defined OP_AND #define PROCESS_ELEM dstelem = srcelem1 & srcelem2 diff --git a/modules/core/test/ocl/test_arithm.cpp b/modules/core/test/ocl/test_arithm.cpp index c574d004f3..ed6414bf4c 100644 --- a/modules/core/test/ocl/test_arithm.cpp +++ b/modules/core/test/ocl/test_arithm.cpp @@ -119,7 +119,6 @@ PARAM_TEST_CASE(ArithmTestBase, MatDepth, Channels, bool) bool use_roi; cv::Scalar val; - // declare Mat + UMat mirrors TEST_DECLARE_INPUT_PARAMETER(src1) TEST_DECLARE_INPUT_PARAMETER(src2) TEST_DECLARE_INPUT_PARAMETER(mask) @@ -281,6 +280,614 @@ OCL_TEST_P(Subtract, Scalar_Mask) } } +//////////////////////////////// Mul ///////////////////////////////////////////////// + +typedef ArithmTestBase Mul; + +OCL_TEST_P(Mul, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +OCL_TEST_P(Mul, DISABLED_Scalar) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::multiply(src1_roi, val, dst1_roi)); + OCL_ON(cv::multiply(val, usrc1_roi, udst1_roi)); + + Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1); + } +} + +OCL_TEST_P(Mul, DISABLED_Mat_Scale) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::multiply(src1_roi, src2_roi, dst1_roi, val[0])); + OCL_ON(cv::multiply(usrc1_roi, usrc2_roi, udst1_roi, val[0])); + + Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1); + } +} + +//////////////////////////////// Div ///////////////////////////////////////////////// + +typedef ArithmTestBase Div; + +OCL_TEST_P(Div, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::divide(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::divide(usrc1_roi, usrc2_roi, udst1_roi)); + Near(1); + } +} + +OCL_TEST_P(Div, DISABLED_Scalar) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::divide(val, src1_roi, dst1_roi)); + OCL_ON(cv::divide(val, usrc1_roi, udst1_roi)); + + Near(udst1_roi.depth() >= CV_32F ? 1e-3 : 1); + } +} + +OCL_TEST_P(Div, Mat_Scale) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::divide(src1_roi, src2_roi, dst1_roi, val[0])); + OCL_ON(cv::divide(usrc1_roi, usrc2_roi, udst1_roi, val[0])); + + Near(udst1_roi.depth() >= CV_32F ? 4e-3 : 1); + } +} + + +OCL_TEST_P(Div, DISABLED_Mat_Scalar_Scale) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::divide(src1_roi, val, dst1_roi, val[0])); + OCL_ON(cv::divide(usrc1_roi, val, udst1_roi, val[0])); + + Near(udst1_roi.depth() >= CV_32F ? 4e-3 : 1); + } +} + +//////////////////////////////// Min/Max ///////////////////////////////////////////////// + +typedef ArithmTestBase Min; + +OCL_TEST_P(Min, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::max(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::max(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +typedef ArithmTestBase Max; + +OCL_TEST_P(Max, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::min(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::min(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +//////////////////////////////// Absdiff ///////////////////////////////////////////////// + +typedef ArithmTestBase Absdiff; + +OCL_TEST_P(Absdiff, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::absdiff(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::absdiff(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +OCL_TEST_P(Absdiff, Scalar) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::absdiff(src1_roi, val, dst1_roi)); + OCL_ON(cv::absdiff(usrc1_roi, val, udst1_roi)); + Near(1e-5); + } +} + +//////////////////////////////// CartToPolar ///////////////////////////////////////////////// + +typedef ArithmTestBase CartToPolar; + +OCL_TEST_P(CartToPolar, angleInDegree) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi, true)); + OCL_ON(cv::cartToPolar(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi, true)); + Near(0.5); + Near1(0.5); + } +} + +OCL_TEST_P(CartToPolar, angleInRadians) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi)); + OCL_ON(cv::cartToPolar(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi)); + Near(0.5); + Near1(0.5); + } +} + +//////////////////////////////// PolarToCart ///////////////////////////////////////////////// + +typedef ArithmTestBase PolarToCart; + +OCL_TEST_P(PolarToCart, angleInDegree) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi, true)); + OCL_ON(cv::polarToCart(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi, true)); + + Near(0.5); + Near1(0.5); + } +} + +OCL_TEST_P(PolarToCart, angleInRadians) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi)); + OCL_ON(cv::polarToCart(usrc1_roi, usrc2_roi, udst1_roi, udst2_roi)); + + Near(0.5); + Near1(0.5); + } +} + +//////////////////////////////// Transpose ///////////////////////////////////////////////// + +typedef ArithmTestBase Transpose; + +OCL_TEST_P(Transpose, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::transpose(src1_roi, dst1_roi)); + OCL_ON(cv::transpose(usrc1_roi, udst1_roi)); + + Near(1e-5); + } +} + +OCL_TEST_P(Transpose, SquareInplace) +{ + const int type = CV_MAKE_TYPE(depth, cn); + + for (int j = 0; j < test_loop_times; j++) + { + Size roiSize = randomSize(1, MAX_VALUE); + roiSize.height = roiSize.width; // make it square + + Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0); + randomSubMat(src1, src1_roi, roiSize, srcBorder, type, 5, 16); + + UMAT_UPLOAD_OUTPUT_PARAMETER(src1); + + OCL_OFF(cv::transpose(src1_roi, src1_roi)); + OCL_ON(cv::transpose(usrc1_roi, usrc1_roi)); + + EXPECT_MAT_NEAR(src1, usrc1, 0.0); + EXPECT_MAT_NEAR(src1_roi, usrc1_roi, 0.0); + } +} + +//////////////////////////////// Bitwise_and ///////////////////////////////////////////////// + +typedef ArithmTestBase Bitwise_and; + +OCL_TEST_P(Bitwise_and, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_and(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::bitwise_and(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +OCL_TEST_P(Bitwise_and, Mat_Mask) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_and(src1_roi, src2_roi, dst1_roi, mask_roi)); + OCL_ON(cv::bitwise_and(usrc1_roi, usrc2_roi, udst1_roi, umask_roi)); + Near(0); + } +} + +OCL_TEST_P(Bitwise_and, Scalar) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_and(src1_roi, val, dst1_roi)); + OCL_ON(cv::bitwise_and(usrc1_roi, val, udst1_roi)); + Near(1e-5); + } +} + +OCL_TEST_P(Bitwise_and, Scalar_Mask) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_and(src1_roi, val, dst1_roi, mask_roi)); + OCL_ON(cv::bitwise_and(usrc1_roi, val, udst1_roi, umask_roi)); + Near(1e-5); + } +} + +//////////////////////////////// Bitwise_or ///////////////////////////////////////////////// + +typedef ArithmTestBase Bitwise_or; + +OCL_TEST_P(Bitwise_or, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_or(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::bitwise_or(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +OCL_TEST_P(Bitwise_or, Mat_Mask) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_or(src1_roi, src2_roi, dst1_roi, mask_roi)); + OCL_ON(cv::bitwise_or(usrc1_roi, usrc2_roi, udst1_roi, umask_roi)); + Near(0); + } +} + +OCL_TEST_P(Bitwise_or, Scalar) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_or(src1_roi, val, dst1_roi)); + OCL_ON(cv::bitwise_or(usrc1_roi, val, udst1_roi)); + Near(1e-5); + } +} + +OCL_TEST_P(Bitwise_or, Scalar_Mask) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_or(src1_roi, val, dst1_roi, mask_roi)); + OCL_ON(cv::bitwise_or(val, usrc1_roi, udst1_roi, umask_roi)); + Near(1e-5); + } +} + +//////////////////////////////// Bitwise_xor ///////////////////////////////////////////////// + +typedef ArithmTestBase Bitwise_xor; + +OCL_TEST_P(Bitwise_xor, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_xor(src1_roi, src2_roi, dst1_roi)); + OCL_ON(cv::bitwise_xor(usrc1_roi, usrc2_roi, udst1_roi)); + Near(0); + } +} + +OCL_TEST_P(Bitwise_xor, Mat_Mask) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_xor(src1_roi, src2_roi, dst1_roi, mask_roi)); + OCL_ON(cv::bitwise_xor(usrc1_roi, usrc2_roi, udst1_roi, umask_roi)); + Near(0); + } +} + +OCL_TEST_P(Bitwise_xor, Scalar) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_xor(src1_roi, val, dst1_roi)); + OCL_ON(cv::bitwise_xor(usrc1_roi, val, udst1_roi)); + Near(1e-5); + } +} + +OCL_TEST_P(Bitwise_xor, Scalar_Mask) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_xor(src1_roi, val, dst1_roi, mask_roi)); + OCL_ON(cv::bitwise_xor(usrc1_roi, val, udst1_roi, umask_roi)); + Near(1e-5); + } +} + +//////////////////////////////// Bitwise_not ///////////////////////////////////////////////// + +typedef ArithmTestBase Bitwise_not; + +OCL_TEST_P(Bitwise_not, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::bitwise_not(src1_roi, dst1_roi)); + OCL_ON(cv::bitwise_not(usrc1_roi, udst1_roi)); + Near(0); + } +} + +//////////////////////////////// Compare ///////////////////////////////////////////////// + +typedef ArithmTestBase Compare; + +OCL_TEST_P(Compare, Mat) +{ + int cmp_codes[] = { CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE }; + int cmp_num = sizeof(cmp_codes) / sizeof(int); + + for (int i = 0; i < cmp_num; ++i) + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::compare(src1_roi, src2_roi, dst1_roi, cmp_codes[i])); + OCL_ON(cv::compare(usrc1_roi, usrc2_roi, udst1_roi, cmp_codes[i])); + + Near(0); + } +} + +//////////////////////////////// Pow ///////////////////////////////////////////////// + +typedef ArithmTestBase Pow; + +OCL_TEST_P(Pow, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + double p = 4.5; + + OCL_OFF(cv::pow(src1_roi, p, dst1_roi)); + OCL_ON(cv::pow(usrc1_roi, p, udst1_roi)); + + Near(1); + } +} + +//////////////////////////////// AddWeighted ///////////////////////////////////////////////// + +typedef ArithmTestBase AddWeighted; + +OCL_TEST_P(AddWeighted, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + const double alpha = 2.0, beta = 1.0, gama = 3.0; + + OCL_OFF(cv::addWeighted(src1_roi, alpha, src2_roi, beta, gama, dst1_roi)); + OCL_ON(cv::addWeighted(usrc1_roi, alpha, usrc2_roi, beta, gama, udst1_roi)); + + Near(3e-4); + } +} + +//////////////////////////////// setIdentity ///////////////////////////////////////////////// + +typedef ArithmTestBase SetIdentity; + +OCL_TEST_P(SetIdentity, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + OCL_OFF(cv::setIdentity(dst1_roi, val)); + OCL_ON(cv::setIdentity(udst1_roi, val)); + + Near(0); + } +} + +//// Repeat + +struct RepeatTestCase : + public ArithmTestBase +{ + int nx, ny; + + virtual void generateTestData() + { + const int type = CV_MAKE_TYPE(depth, cn); + + nx = 2;//randomInt(1, 4); + ny = 2;//randomInt(1, 4); + + Size srcRoiSize = randomSize(1, MAX_VALUE); + Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0); + randomSubMat(src1, src1_roi, srcRoiSize, srcBorder, type, 2, 11); + + Size dstRoiSize(srcRoiSize.width * nx, srcRoiSize.height * ny); + Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0); + randomSubMat(dst1, dst1_roi, dstRoiSize, dst1Border, type, 5, 16); + + UMAT_UPLOAD_INPUT_PARAMETER(src1) + UMAT_UPLOAD_OUTPUT_PARAMETER(dst1) + } +}; + +typedef RepeatTestCase Repeat; + +OCL_TEST_P(Repeat, DISABLED_Mat) +{ + for (int i = 0; i < test_loop_times; ++i) + { + generateTestData(); + + OCL_OFF(cv::repeat(src1_roi, ny, nx, dst1_roi)); + OCL_ON(cv::repeat(usrc1_roi, ny, nx, udst1_roi)); + + Near(); + } +} + +//////////////////////////////// CountNonZero ///////////////////////////////////////////////// + +typedef ArithmTestBase CountNonZero; + +OCL_TEST_P(CountNonZero, MAT) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + int cpures, gpures; + OCL_OFF(cpures = cv::countNonZero(src1_roi)); + OCL_ON(gpures = cv::countNonZero(usrc1_roi)); + + EXPECT_EQ(cpures, gpures); + } +} + +//////////////////////////////// Sum ///////////////////////////////////////////////// + +typedef ArithmTestBase Sum; + +OCL_TEST_P(Sum, MAT) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + Scalar cpures, gpures; + OCL_OFF(cpures = cv::sum(src1_roi)); + OCL_ON(gpures = cv::sum(usrc1_roi)); + + for (int i = 0; i < cn; ++i) + EXPECT_NEAR(cpures[i], gpures[i], 0.1); + } +} + +//////////////////////////////// meanStdDev ///////////////////////////////////////////////// + +typedef ArithmTestBase MeanStdDev; + +OCL_TEST_P(MeanStdDev, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + Scalar cpu_mean, cpu_stddev; + Scalar gpu_mean, gpu_stddev; + + OCL_OFF(cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev)); + OCL_ON(cv::meanStdDev(usrc1_roi, gpu_mean, gpu_stddev)); + + for (int i = 0; i < cn; ++i) + { + EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1); + EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1); + } + } +} + + //////////////////////////////////////// Log ///////////////////////////////////////// typedef ArithmTestBase Log; @@ -359,13 +966,33 @@ OCL_TEST_P(Magnitude, Mat) //////////////////////////////////////// Instantiation ///////////////////////////////////////// -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Lut, Combine(::testing::Values(CV_8U, CV_8S), OCL_ALL_DEPTHS, ::testing::Values(1, 2, 3, 4), Bool(), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Add, Combine(OCL_ALL_DEPTHS, ::testing::Values(1, 2, 4), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Subtract, Combine(OCL_ALL_DEPTHS, ::testing::Values(1, 2, 4), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Log, Combine(::testing::Values(CV_32F, CV_64F), ::testing::Values(1, 2, 3, 4), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Exp, Combine(::testing::Values(CV_32F, CV_64F), ::testing::Values(1, 2, 3, 4), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Phase, Combine(::testing::Values(CV_32F, CV_64F), ::testing::Values(1, 2, 3, 4), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Arithm, Magnitude, Combine(::testing::Values(CV_32F, CV_64F), ::testing::Values(1, 2, 3, 4), Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Lut, Combine(::testing::Values(CV_8U, CV_8S), OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool(), Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Add, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Subtract, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Log, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Exp, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Phase, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Magnitude, Combine(::testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Mul, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Div, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Min, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Max, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Absdiff, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, CartToPolar, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, PolarToCart, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Transpose, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_and, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_not, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_xor, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Bitwise_or, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Pow, Combine(testing::Values(CV_32F, CV_64F), OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Compare, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, AddWeighted, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, SetIdentity, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Repeat, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, CountNonZero, Combine(OCL_ALL_DEPTHS, testing::Values(Channels(1)), Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Sum, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, MeanStdDev, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); } } // namespace cvtest::ocl