From 4b719215269d67c64040b48f2088e65262bbb3d9 Mon Sep 17 00:00:00 2001 From: mlyashko Date: Thu, 27 Mar 2014 17:08:05 +0400 Subject: [PATCH 1/3] both tests by picture and rand mat --- modules/imgproc/test/ocl/test_histogram.cpp | 40 ++++++++++++++++++++- modules/ts/include/opencv2/ts/ocl_test.hpp | 11 ++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/test/ocl/test_histogram.cpp b/modules/imgproc/test/ocl/test_histogram.cpp index 0a27907b6..7d52fc1de 100644 --- a/modules/imgproc/test/ocl/test_histogram.cpp +++ b/modules/imgproc/test/ocl/test_histogram.cpp @@ -13,6 +13,7 @@ // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. +// Copyright (C) 2013-2014, Itseez, Inc, all rights reserved. // Third party copyrights are property of their respective owners. // // @Authors @@ -144,6 +145,36 @@ PARAM_TEST_CASE(CalcBackProject, MatDepth, int, bool) scale = randomDouble(0.1, 1); } + + virtual void test_by_pict() + { + Mat frame1 = readImage("optflow/RubberWhale1.png", IMREAD_GRAYSCALE); + + UMat usrc; + frame1.copyTo(usrc); + int histSize = randomInt(3, 29); + float hue_range[] = { 0, 180 }; + const float* ranges = { hue_range }; + + //compute histogram + calcHist(&frame1, 1, 0, Mat(), hist, 1, &histSize, &ranges, true, false); + normalize(hist, hist, 0, 255, NORM_MINMAX, -1, Mat()); + + Mat dst; + UMat udst, src, uhist; + hist.copyTo(uhist); + std::vector uims; + uims.push_back(usrc); + std::vector urngs; + urngs.push_back(0); + urngs.push_back(180); + std::vector chs; + chs.push_back(0); + + OCL_OFF(calcBackProject(&frame1, 1, 0, hist, dst, &ranges, 1, true)); + OCL_ON(calcBackProject(uims, chs, uhist, udst, urngs, 1.0)); + EXPECT_MAT_NEAR(dst, udst, 0.0); + } }; //////////////////////////////// CalcBackProject ////////////////////////////////////////////// @@ -157,7 +188,14 @@ OCL_TEST_P(CalcBackProject, Mat) OCL_OFF(cv::calcBackProject(images_roi, channels, hist_roi, dst_roi, ranges, scale)); OCL_ON(cv::calcBackProject(uimages_roi, channels, uhist_roi, udst_roi, ranges, scale)); - OCL_EXPECT_MATS_NEAR(dst, 0.0); + Size dstSize = dst_roi.size(); + int nDiffs = (int)(0.03f*dstSize.height*dstSize.width); + + //check if the dst mats are the same except 3% difference + EXPECT_MAT_N_DIFF(dst_roi, udst_roi, nDiffs); + + //check in addition on given image + test_by_pict(); } } diff --git a/modules/ts/include/opencv2/ts/ocl_test.hpp b/modules/ts/include/opencv2/ts/ocl_test.hpp index 0f0d9657f..28ff67491 100644 --- a/modules/ts/include/opencv2/ts/ocl_test.hpp +++ b/modules/ts/include/opencv2/ts/ocl_test.hpp @@ -85,6 +85,17 @@ do \ << "Size: " << mat1.size() << std::endl; \ } while ((void)0, 0) +#define EXPECT_MAT_N_DIFF(mat1, mat2, num) \ +do \ +{ \ + ASSERT_EQ(mat1.type(), mat2.type()); \ + ASSERT_EQ(mat1.size(), mat2.size()); \ + Mat diff; \ + absdiff(mat1, mat2, diff); \ + EXPECT_LE(countNonZero(diff.reshape(1)), num) \ + << "Size: " << mat1.size() << std::endl; \ +} while ((void)0, 0) + #define OCL_EXPECT_MATS_NEAR(name, eps) \ do \ { \ From 4c5de04efb88a28a750399adc4db2010b01cc8bf Mon Sep 17 00:00:00 2001 From: mlyashko Date: Mon, 31 Mar 2014 10:58:15 +0400 Subject: [PATCH 2/3] bug fix --- modules/imgproc/test/ocl/test_histogram.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/imgproc/test/ocl/test_histogram.cpp b/modules/imgproc/test/ocl/test_histogram.cpp index 7d52fc1de..5b863bdd2 100644 --- a/modules/imgproc/test/ocl/test_histogram.cpp +++ b/modules/imgproc/test/ocl/test_histogram.cpp @@ -154,15 +154,16 @@ PARAM_TEST_CASE(CalcBackProject, MatDepth, int, bool) frame1.copyTo(usrc); int histSize = randomInt(3, 29); float hue_range[] = { 0, 180 }; - const float* ranges = { hue_range }; + const float* ranges1 = { hue_range }; + Mat hist1; //compute histogram - calcHist(&frame1, 1, 0, Mat(), hist, 1, &histSize, &ranges, true, false); - normalize(hist, hist, 0, 255, NORM_MINMAX, -1, Mat()); + calcHist(&frame1, 1, 0, Mat(), hist1, 1, &histSize, &ranges1, true, false); + normalize(hist1, hist1, 0, 255, NORM_MINMAX, -1, Mat()); - Mat dst; - UMat udst, src, uhist; - hist.copyTo(uhist); + Mat dst1; + UMat udst1, src, uhist1; + hist1.copyTo(uhist1); std::vector uims; uims.push_back(usrc); std::vector urngs; @@ -171,9 +172,9 @@ PARAM_TEST_CASE(CalcBackProject, MatDepth, int, bool) std::vector chs; chs.push_back(0); - OCL_OFF(calcBackProject(&frame1, 1, 0, hist, dst, &ranges, 1, true)); - OCL_ON(calcBackProject(uims, chs, uhist, udst, urngs, 1.0)); - EXPECT_MAT_NEAR(dst, udst, 0.0); + OCL_OFF(calcBackProject(&frame1, 1, 0, hist1, dst1, &ranges1, 1, true)); + OCL_ON(calcBackProject(uims, chs, uhist1, udst1, urngs, 1.0)); + EXPECT_MAT_NEAR(dst1, udst1, 0.0); } }; From 5acd17879039027d3c5064bf14bc68955b30d427 Mon Sep 17 00:00:00 2001 From: mlyashko Date: Mon, 31 Mar 2014 14:57:03 +0400 Subject: [PATCH 3/3] copyright fix --- modules/imgproc/test/ocl/test_histogram.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/imgproc/test/ocl/test_histogram.cpp b/modules/imgproc/test/ocl/test_histogram.cpp index 5b863bdd2..c13556b30 100644 --- a/modules/imgproc/test/ocl/test_histogram.cpp +++ b/modules/imgproc/test/ocl/test_histogram.cpp @@ -13,7 +13,7 @@ // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. -// Copyright (C) 2013-2014, Itseez, Inc, all rights reserved. +// Copyright (C) 2014, Itseez, Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // @Authors