From 1592234f1a54a1cc8ce0040f0b29b0b6ba9055c3 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 6 Jan 2014 00:12:13 +0400 Subject: [PATCH 1/4] added mask support to cv::norm, cv::meanStdDev --- modules/core/test/ocl/test_arithm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/test/ocl/test_arithm.cpp b/modules/core/test/ocl/test_arithm.cpp index 9d5fcf335c..a2165d256c 100644 --- a/modules/core/test/ocl/test_arithm.cpp +++ b/modules/core/test/ocl/test_arithm.cpp @@ -1011,6 +1011,7 @@ OCL_TEST_P(Phase, angleInDegree) } } + OCL_TEST_P(Phase, angleInRadians) { for (int j = 0; j < test_loop_times; j++) From a01e81c8f711a9218a5ed9968cc8b26671c5db05 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 7 Jan 2014 15:08:48 +0400 Subject: [PATCH 2/4] added some performance tests --- modules/core/perf/opencl/perf_arithm.cpp | 76 ++++++++++++++++++++++++ modules/core/src/mathfuncs.cpp | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index cb06ac4793..5bc2a5aec7 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -814,6 +814,82 @@ OCL_PERF_TEST_P(NormalizeFixture, Normalize, SANITY_CHECK(dst, 5e-2); } +///////////// ConvertScaleAbs //////////////////////// + +typedef Size_MatType ConvertScaleAbsFixture; + +OCL_PERF_TEST_P(ConvertScaleAbsFixture, ConvertScaleAbs, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params), cn = CV_MAT_CN(type); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type), dst(srcSize, CV_8UC(cn)); + declare.in(src, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::convertScaleAbs(src, dst, 0.5, 2); + + SANITY_CHECK(dst); +} + +///////////// PatchNaNs //////////////////////// + +typedef Size_MatType PatchNaNsFixture; + +OCL_PERF_TEST_P(PatchNaNsFixture, PatchNaNs, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32FC1, CV_32FC4))) +{ + const Size_MatType_t params = GetParam(); + Size srcSize = get<0>(params); + const int type = get<1>(params), cn = CV_MAT_CN(type); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src(srcSize, type); + declare.in(src, WARMUP_RNG).out(src); + + // generating NaNs + { + Mat src_ = src.getMat(ACCESS_RW); + srcSize.width *= cn; + for (int y = 0; y < srcSize.height; ++y) + { + float * const ptr = src_.ptr(y); + for (int x = 0; x < srcSize.width; ++x) + ptr[x] = (x + y) % 2 == 0 ? std::numeric_limits::quiet_NaN() : ptr[x]; + } + } + + OCL_TEST_CYCLE() cv::patchNaNs(src, 17.7); + + SANITY_CHECK(src); +} + + +///////////// ScaleAdd //////////////////////// + +typedef Size_MatType ScaleAddFixture; + +OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd, + ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES)) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type); + declare.in(src1, src2, WARMUP_RNG).out(dst); + + OCL_TEST_CYCLE() cv::scaleAdd(src1, 0.6, src2, dst); + + SANITY_CHECK(dst, 1e-6); +} + } } // namespace cvtest::ocl #endif // HAVE_OPENCL diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 90e0d74a49..15bd93ef53 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -2375,7 +2375,7 @@ static bool ocl_patchNaNs( InputOutputArray _a, float value ) int cn = a.channels(); k.args(ocl::KernelArg::ReadOnlyNoSize(a), - ocl::KernelArg::WriteOnly(a), (float)value); + ocl::KernelArg::WriteOnly(a, cn), (float)value); size_t globalsize[2] = { a.cols * cn, a.rows }; return k.run(2, globalsize, NULL, false); From 2e5e278271c00cd78b3a39c31de3e390c2b1c33c Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 7 Jan 2014 20:17:45 +0400 Subject: [PATCH 3/4] added cv::PSNR performance test --- modules/core/perf/opencl/perf_arithm.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index 5bc2a5aec7..fc6ce0840a 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -890,6 +890,28 @@ OCL_PERF_TEST_P(ScaleAddFixture, ScaleAdd, SANITY_CHECK(dst, 1e-6); } +///////////// PSNR //////////////////////// + +typedef Size_MatType PSNRFixture; + +OCL_PERF_TEST_P(PSNRFixture, PSNR, + ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4))) +{ + const Size_MatType_t params = GetParam(); + const Size srcSize = get<0>(params); + const int type = get<1>(params); + + checkDeviceMaxMemoryAllocSize(srcSize, type); + + double psnr = 0; + UMat src1(srcSize, type), src2(srcSize, type); + declare.in(src1, src2, WARMUP_RNG); + + OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2); + + SANITY_CHECK(psnr, 1e-6, ERROR_RELATIVE); +} + } } // namespace cvtest::ocl #endif // HAVE_OPENCL From da2790249e06235d613bad077c121ad058d87e00 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 7 Jan 2014 20:32:22 +0400 Subject: [PATCH 4/4] added NORM_L2SQR type to cv::norm --- modules/core/perf/opencl/perf_arithm.cpp | 2 +- modules/core/src/stat.cpp | 10 +++++----- modules/core/test/ocl/test_arithm.cpp | 21 ++++++++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index fc6ce0840a..4eae4897e0 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -909,7 +909,7 @@ OCL_PERF_TEST_P(PSNRFixture, PSNR, OCL_TEST_CYCLE() psnr = cv::PSNR(src1, src2); - SANITY_CHECK(psnr, 1e-6, ERROR_RELATIVE); + SANITY_CHECK(psnr, 1e-4, ERROR_RELATIVE); } } } // namespace cvtest::ocl diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index a2cdeaf3e8..eac823995a 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -1902,7 +1902,7 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double & bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0, haveMask = _mask.kind() != _InputArray::NONE; - if ( !(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2) || + if ( !(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR) || (!doubleSupport && depth == CV_64F) || (normType == NORM_INF && haveMask && cn != 1)) return false; @@ -1937,12 +1937,12 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double & cv::minMaxIdx(haveMask ? abssrc : abssrc.reshape(1), NULL, &result, NULL, NULL, _mask); } - else if (normType == NORM_L1 || normType == NORM_L2) + else if (normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR) { Scalar sc; bool unstype = depth == CV_8U || depth == CV_16U; - if ( !ocl_sum(haveMask ? src : src.reshape(1), sc, normType == NORM_L2 ? + if ( !ocl_sum(haveMask ? src : src.reshape(1), sc, normType == NORM_L2 || normType == NORM_L2SQR ? OCL_OP_SUM_SQR : (unstype ? OCL_OP_SUM : OCL_OP_SUM_ABS), _mask) ) return false; @@ -1953,7 +1953,7 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double & for (int i = 0; i < cn; ++i) s += sc[i]; - result = normType == NORM_L1 ? s : std::sqrt(s); + result = normType == NORM_L1 || normType == NORM_L2SQR ? s : std::sqrt(s); } return true; @@ -2261,7 +2261,7 @@ static bool ocl_norm( InputArray _src1, InputArray _src2, int normType, double & bool relative = (normType & NORM_RELATIVE) != 0; normType &= ~NORM_RELATIVE; - if ( !(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2) || + if ( !(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR) || (!doubleSupport && depth == CV_64F)) return false; diff --git a/modules/core/test/ocl/test_arithm.cpp b/modules/core/test/ocl/test_arithm.cpp index a2165d256c..ff85e6c248 100644 --- a/modules/core/test/ocl/test_arithm.cpp +++ b/modules/core/test/ocl/test_arithm.cpp @@ -1011,7 +1011,6 @@ OCL_TEST_P(Phase, angleInDegree) } } - OCL_TEST_P(Phase, angleInRadians) { for (int j = 0; j < test_loop_times; j++) @@ -1548,6 +1547,25 @@ OCL_TEST_P(PatchNaNs, Mat) } } +//////////////////////////////// Psnr //////////////////////////////////////////////// + +typedef ArithmTestBase Psnr; + +OCL_TEST_P(Psnr, Mat) +{ + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + + double cpuRes = 0, gpuRes = 0; + + OCL_OFF(cpuRes = cv::PSNR(src1_roi, src2_roi)); + OCL_ON(gpuRes = cv::PSNR(usrc1_roi, usrc2_roi)); + + EXPECT_PRED3(relativeError, cpuRes, gpuRes, 1e-6); + } +} + //////////////////////////////////////// Instantiation ///////////////////////////////////////// OCL_INSTANTIATE_TEST_CASE_P(Arithm, Lut, Combine(::testing::Values(CV_8U, CV_8S), OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool(), Bool())); @@ -1587,6 +1605,7 @@ OCL_INSTANTIATE_TEST_CASE_P(Arithm, InRange, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHA OCL_INSTANTIATE_TEST_CASE_P(Arithm, ConvertScaleAbs, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); OCL_INSTANTIATE_TEST_CASE_P(Arithm, ScaleAdd, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, Bool())); OCL_INSTANTIATE_TEST_CASE_P(Arithm, PatchNaNs, Combine(OCL_ALL_CHANNELS, Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Arithm, Psnr, Combine(::testing::Values((MatDepth)CV_8U), OCL_ALL_CHANNELS, Bool())); } } // namespace cvtest::ocl