diff --git a/modules/imgproc/perf/opencl/perf_filters.cpp b/modules/imgproc/perf/opencl/perf_filters.cpp index b4e29ae67f..a179f7d009 100644 --- a/modules/imgproc/perf/opencl/perf_filters.cpp +++ b/modules/imgproc/perf/opencl/perf_filters.cpp @@ -313,6 +313,62 @@ OCL_PERF_TEST_P(Filter2DFixture, Filter2D, SANITY_CHECK(dst, eps); } +///////////// SepFilter2D ///////////// + +typedef FilterFixture OCL_SepFilter2D; + +PERF_TEST_P_(OCL_SepFilter2D, SepFilter2D) +{ + const FilterParams& params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), ksize = get<2>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type), dst(srcSize, type); + declare.in(src, WARMUP_RNG).out(dst); + + Mat kernelX(1, ksize, CV_32FC1); + randu(kernelX, -3.0, 3.0); + Mat kernelY(1, ksize, CV_32FC1); + randu(kernelY, -3.0, 3.0); + + OCL_TEST_CYCLE() cv::sepFilter2D(src, dst, -1, kernelX, kernelY, cv::Point(-1, -1), 1.0f, cv::BORDER_CONSTANT); + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(OCL_SepFilter2D, SepFilter2D_BitExact) +{ + const FilterParams& params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), ksize = get<2>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type), dst(srcSize, type); + declare.in(src, WARMUP_RNG).out(dst); + + Mat kernelX(1, ksize, CV_32SC1); + randu(kernelX, -16.0, 16.0); + kernelX.convertTo(kernelX, CV_32FC1, 1/16.0f, 0); + Mat kernelY(1, ksize, CV_32SC1); + randu(kernelY, -16.0, 16.0); + kernelY.convertTo(kernelY, CV_32FC1, 1/16.0f, 0); + + OCL_TEST_CYCLE() cv::sepFilter2D(src, dst, -1, kernelX, kernelY, cv::Point(-1, -1), 1.0f, cv::BORDER_CONSTANT); + + SANITY_CHECK_NOTHING(); +} + +INSTANTIATE_TEST_CASE_P(/*nothing*/, OCL_SepFilter2D, + ::testing::Combine( + ::testing::Values(sz1080p), + OCL_TEST_TYPES, + OCL_PERF_ENUM(3, 5, 7, 9, 11) + ) +); + ///////////// Bilateral //////////////////////// typedef TestBaseWithParam BilateralFixture; diff --git a/modules/imgproc/test/ocl/test_sepfilter2d.cpp b/modules/imgproc/test/ocl/test_sepfilter2d.cpp index 9b1f1690ae..12f247ed36 100644 --- a/modules/imgproc/test/ocl/test_sepfilter2d.cpp +++ b/modules/imgproc/test/ocl/test_sepfilter2d.cpp @@ -73,7 +73,7 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool) useRoi = GET_PARAM(4); } - void random_roi() + void random_roi(bool bitExact) { Size ksize = randomSize(kernelMinSize, kernelMaxSize); if (1 != ksize.width % 2) @@ -81,11 +81,19 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool) if (1 != ksize.height % 2) ksize.height++; - Mat temp = randomMat(Size(ksize.width, 1), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE); + Mat temp = randomMat(Size(ksize.width, 1), CV_32FC1, -0.5, 1.0); cv::normalize(temp, kernelX, 1.0, 0.0, NORM_L1); - temp = randomMat(Size(1, ksize.height), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE); + temp = randomMat(Size(1, ksize.height), CV_32FC1, -0.5, 1.0); cv::normalize(temp, kernelY, 1.0, 0.0, NORM_L1); + if (bitExact) + { + kernelX.convertTo(temp, CV_32S, 256); + temp.convertTo(kernelX, CV_32F, 1.0 / 256); + kernelY.convertTo(temp, CV_32S, 256); + temp.convertTo(kernelY, CV_32F, 1.0 / 256); + } + Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE); Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE); @@ -96,6 +104,11 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool) anchor.x = anchor.y = -1; delta = randomDouble(-100, 100); + if (bitExact) + { + delta = (int)(delta * 256) / 256.0; + } + UMAT_UPLOAD_INPUT_PARAMETER(src); UMAT_UPLOAD_OUTPUT_PARAMETER(dst); } @@ -110,7 +123,7 @@ OCL_TEST_P(SepFilter2D, Mat) { for (int j = 0; j < test_loop_times + 3; j++) { - random_roi(); + random_roi(false); OCL_OFF(cv::sepFilter2D(src_roi, dst_roi, -1, kernelX, kernelY, anchor, delta, borderType)); OCL_ON(cv::sepFilter2D(usrc_roi, udst_roi, -1, kernelX, kernelY, anchor, delta, borderType)); @@ -119,6 +132,22 @@ OCL_TEST_P(SepFilter2D, Mat) } } +OCL_TEST_P(SepFilter2D, Mat_BitExact) +{ + for (int j = 0; j < test_loop_times + 3; j++) + { + random_roi(true); + + OCL_OFF(cv::sepFilter2D(src_roi, dst_roi, -1, kernelX, kernelY, anchor, delta, borderType)); + OCL_ON(cv::sepFilter2D(usrc_roi, udst_roi, -1, kernelX, kernelY, anchor, delta, borderType)); + + if (src_roi.depth() < CV_32F) + Near(0.0); + else + Near(1e-3); + } +} + OCL_INSTANTIATE_TEST_CASE_P(ImageProc, SepFilter2D, Combine( Values(CV_8U, CV_32F),