diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index 1b1ceac2c..05c1a6e40 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -1306,9 +1306,10 @@ namespace cv { static bool ocl_LUT(InputArray _src, InputArray _lut, OutputArray _dst) { - int dcn = _dst.channels(), lcn = _lut.channels(), dtype = _dst.type(); + int dtype = _dst.type(), lcn = _lut.channels(), dcn = CV_MAT_CN(dtype), ddepth = CV_MAT_DEPTH(dtype); + bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; - if (_src.dims() > 2) + if (_src.dims() > 2 || (!doubleSupport && ddepth == CV_64F)) return false; UMat src = _src.getUMat(), lut = _lut.getUMat(); @@ -1316,8 +1317,9 @@ static bool ocl_LUT(InputArray _src, InputArray _lut, OutputArray _dst) UMat dst = _dst.getUMat(); ocl::Kernel k("LUT", ocl::core::lut_oclsrc, - format("-D dcn=%d -D lcn=%d -D srcT=%s -D dstT=%s", dcn, lcn, - ocl::typeToStr(src.depth()), ocl::typeToStr(dst.depth()))); + format("-D dcn=%d -D lcn=%d -D srcT=%s -D dstT=%s%s", dcn, lcn, + ocl::typeToStr(src.depth()), ocl::typeToStr(ddepth), + doubleSupport ? " -D DOUBLE_SUPPORT" : "")); k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::ReadOnlyNoSize(lut), ocl::KernelArg::WriteOnly(dst)); diff --git a/modules/core/test/ocl/test_arithm.cpp b/modules/core/test/ocl/test_arithm.cpp index 045fbd7c4..e14fd67f5 100644 --- a/modules/core/test/ocl/test_arithm.cpp +++ b/modules/core/test/ocl/test_arithm.cpp @@ -92,8 +92,7 @@ PARAM_TEST_CASE(Lut, MatDepth, MatDepth, Channels, bool, bool) void Near(double threshold = 0.) { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold) } }; @@ -165,14 +164,12 @@ PARAM_TEST_CASE(ArithmTestBase, MatDepth, Channels, bool) void Near(double threshold = 0.) { - EXPECT_MAT_NEAR(dst1, udst1, threshold); - EXPECT_MAT_NEAR(dst1_roi, udst1_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst1, threshold) } void Near1(double threshold = 0.) { - EXPECT_MAT_NEAR(dst2, udst2, threshold); - EXPECT_MAT_NEAR(dst2_roi, udst2_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst2, threshold) } }; @@ -532,8 +529,7 @@ OCL_TEST_P(Transpose, SquareInplace) 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); + OCL_EXPECT_MATS_NEAR(src1, 0) } } diff --git a/modules/core/test/ocl/test_split_merge.cpp b/modules/core/test/ocl/test_split_merge.cpp index 224963cd2..0fa0b1958 100644 --- a/modules/core/test/ocl/test_split_merge.cpp +++ b/modules/core/test/ocl/test_split_merge.cpp @@ -113,8 +113,7 @@ PARAM_TEST_CASE(MergeTestBase, MatDepth, Channels, bool) void Near(double threshold = 0.) { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold); } }; diff --git a/modules/imgproc/test/ocl/test_color.cpp b/modules/imgproc/test/ocl/test_color.cpp index 5bcfa1bac..4c0f8b311 100644 --- a/modules/imgproc/test/ocl/test_color.cpp +++ b/modules/imgproc/test/ocl/test_color.cpp @@ -86,8 +86,7 @@ PARAM_TEST_CASE(CvtColor, MatDepth, bool) void Near(double threshold) { - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); - EXPECT_MAT_NEAR(dst, udst, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold) } void performTest(int channelsIn, int channelsOut, int code, double threshold = 1e-3) diff --git a/modules/imgproc/test/ocl/test_imgproc.cpp b/modules/imgproc/test/ocl/test_imgproc.cpp index 9089b5592..d6799ce45 100644 --- a/modules/imgproc/test/ocl/test_imgproc.cpp +++ b/modules/imgproc/test/ocl/test_imgproc.cpp @@ -97,15 +97,9 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, void Near(double threshold = 0.0, bool relative = false) { if (relative) - { - EXPECT_MAT_NEAR_RELATIVE(dst, udst, threshold); - EXPECT_MAT_NEAR_RELATIVE(dst_roi, udst_roi, threshold); - } + OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold) else - { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); - } + OCL_EXPECT_MATS_NEAR(dst, threshold) } }; @@ -158,10 +152,9 @@ PARAM_TEST_CASE(CopyMakeBorder, MatDepth, // depth UMAT_UPLOAD_OUTPUT_PARAMETER(dst) } - void Near(double threshold = 0.0) + void Near() { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst, 0) } }; @@ -305,15 +298,9 @@ struct Integral : void Near2(double threshold = 0.0, bool relative = false) { if (relative) - { - EXPECT_MAT_NEAR_RELATIVE(dst2, udst2, threshold); - EXPECT_MAT_NEAR_RELATIVE(dst2_roi, udst2_roi, threshold); - } + OCL_EXPECT_MATS_NEAR_RELATIVE(dst2, threshold) else - { - EXPECT_MAT_NEAR(dst2, udst2, threshold); - EXPECT_MAT_NEAR(dst2_roi, udst2_roi, threshold); - } + OCL_EXPECT_MATS_NEAR(dst2, threshold) } }; @@ -412,8 +399,7 @@ PARAM_TEST_CASE(CLAHETest, Size, double, bool) void Near(double threshold = 0.0) { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold) } }; diff --git a/modules/imgproc/test/ocl/test_warp.cpp b/modules/imgproc/test/ocl/test_warp.cpp index c05c33590..d5c75f0da 100644 --- a/modules/imgproc/test/ocl/test_warp.cpp +++ b/modules/imgproc/test/ocl/test_warp.cpp @@ -104,8 +104,7 @@ PARAM_TEST_CASE(WarpTestBase, MatType, Interpolation, bool, bool) void Near(double threshold = 0.0) { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold) } }; @@ -203,8 +202,7 @@ PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool) void Near(double threshold = 0.0) { - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); - EXPECT_MAT_NEAR(dst, udst, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold) } }; @@ -280,8 +278,7 @@ PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair, BorderTy void Near(double threshold = 0.0) { - EXPECT_MAT_NEAR(dst, udst, threshold); - EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold); + OCL_EXPECT_MATS_NEAR(dst, threshold) } }; diff --git a/modules/ts/include/opencv2/ts/ocl_test.hpp b/modules/ts/include/opencv2/ts/ocl_test.hpp index 1b66799ed..b14626553 100644 --- a/modules/ts/include/opencv2/ts/ocl_test.hpp +++ b/modules/ts/include/opencv2/ts/ocl_test.hpp @@ -110,6 +110,26 @@ extern int test_loop_times; << cv::format("Size: %d x %d", mat1.size().width, mat1.size().height) << std::endl; \ } +#define OCL_EXPECT_MATS_NEAR(name, eps) \ +{ \ + EXPECT_MAT_NEAR(name ## _roi, u ## name ## _roi, eps); \ + int nextValue = rng.next(); \ + RNG dataRng1(nextValue), dataRng2(nextValue); \ + dataRng1.fill(name ## _roi, RNG::UNIFORM, Scalar::all(-MAX_VALUE), Scalar::all(MAX_VALUE)); \ + dataRng2.fill(u ## name ## _roi, RNG::UNIFORM, Scalar::all(-MAX_VALUE), Scalar::all(MAX_VALUE)); \ + EXPECT_MAT_NEAR(name, u ## name, 0/*FLT_EPSILON*/); \ +} + +#define OCL_EXPECT_MATS_NEAR_RELATIVE(name, eps) \ +{ \ + EXPECT_MAT_NEAR_RELATIVE(name ## _roi, u ## name ## _roi, eps); \ + int nextValue = rng.next(); \ + RNG dataRng1(nextValue), dataRng2(nextValue); \ + dataRng1.fill(name ## _roi, RNG::UNIFORM, Scalar::all(-MAX_VALUE), Scalar::all(MAX_VALUE)); \ + dataRng2.fill(u ## name ## _roi, RNG::UNIFORM, Scalar::all(-MAX_VALUE), Scalar::all(MAX_VALUE)); \ + EXPECT_MAT_NEAR_RELATIVE(name, u ## name, 0/*FLT_EPSILON*/); \ +} + #define EXPECT_MAT_SIMILAR(mat1, mat2, eps) \ { \ ASSERT_EQ(mat1.type(), mat2.type()); \ @@ -302,7 +322,7 @@ IMPLEMENT_PARAM_CLASS(Channels, int) #define OCL_OFF(fn) cv::ocl::setUseOpenCL(false); fn #define OCL_ON(fn) cv::ocl::setUseOpenCL(true); fn -#define OCL_ALL_DEPTHS Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F) +#define OCL_ALL_DEPTHS Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F) #define OCL_ALL_CHANNELS Values(1, 2, 3, 4) CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_AREA)