From c9c759f7005fdcf985216bcdf633e43d03b900a9 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 2 Nov 2017 13:35:28 +0300 Subject: [PATCH 1/2] ocl: fix moments global_size (should be >= local_size) --- modules/imgproc/src/moments.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/moments.cpp b/modules/imgproc/src/moments.cpp index 00e74f7d93..7e52f1f2fa 100644 --- a/modules/imgproc/src/moments.cpp +++ b/modules/imgproc/src/moments.cpp @@ -510,7 +510,8 @@ static bool ocl_moments( InputArray _src, Moments& m, bool binary) int ntiles = xtiles*ytiles; UMat umbuf(1, ntiles*K, CV_32S); - size_t globalsize[] = {(size_t)xtiles, (size_t)sz.height}, localsize[] = {1, TILE_SIZE}; + size_t globalsize[] = {(size_t)xtiles, std::max((size_t)TILE_SIZE, (size_t)sz.height)}; + size_t localsize[] = {1, TILE_SIZE}; bool ok = k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::PtrWriteOnly(umbuf), xtiles).run(2, globalsize, localsize, true); From 47ae5197a961c0f38806bec9735fc87c787ffc4a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 2 Nov 2017 13:36:04 +0300 Subject: [PATCH 2/2] test: extract OpenCL Moments tests, drop 'coi' parameter --- modules/imgproc/test/test_moments.cpp | 41 +++++++-------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/modules/imgproc/test/test_moments.cpp b/modules/imgproc/test/test_moments.cpp index 5288e5b0cd..a65d5afdcf 100644 --- a/modules/imgproc/test/test_moments.cpp +++ b/modules/imgproc/test/test_moments.cpp @@ -39,6 +39,7 @@ // //M*/ #include "test_precomp.hpp" +#include "opencv2/ts/ocl_test.hpp" using namespace cv; using namespace std; @@ -54,7 +55,7 @@ using namespace std; class CV_MomentsTest : public cvtest::ArrayTest { public: - CV_MomentsTest(); + CV_MomentsTest(bool try_umat); protected: @@ -65,18 +66,17 @@ protected: void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high ); double get_success_error_level( int test_case_idx, int i, int j ); void run_func(); - int coi; bool is_binary; - bool try_umat; + bool try_umat_; }; -CV_MomentsTest::CV_MomentsTest() +CV_MomentsTest::CV_MomentsTest(bool try_umat) : + try_umat_(try_umat) { test_array[INPUT].push_back(NULL); test_array[OUTPUT].push_back(NULL); test_array[REF_OUTPUT].push_back(NULL); - coi = -1; is_binary = false; OCL_TUNING_MODE_ONLY(test_case_count = 10); //element_wise_relative_error = false; @@ -110,40 +110,24 @@ void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx, { RNG& rng = ts->get_rng(); cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types ); - int cn = (cvtest::randInt(rng) % 4) + 1; int depth = cvtest::randInt(rng) % 4; depth = depth == 0 ? CV_8U : depth == 1 ? CV_16U : depth == 2 ? CV_16S : CV_32F; is_binary = cvtest::randInt(rng) % 2 != 0; - if( depth == 0 && !is_binary ) - try_umat = cvtest::randInt(rng) % 5 != 0; - else - try_umat = cvtest::randInt(rng) % 2 != 0; - - if( cn == 2 || try_umat ) - cn = 1; OCL_TUNING_MODE_ONLY( - cn = 1; depth = CV_8U; - try_umat = true; is_binary = false; sizes[INPUT][0] = Size(1024,768) ); - types[INPUT][0] = CV_MAKETYPE(depth, cn); + types[INPUT][0] = CV_MAKETYPE(depth, 1); types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1; sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(MOMENT_COUNT,1); if(CV_MAT_DEPTH(types[INPUT][0])>=CV_32S) sizes[INPUT][0].width = MAX(sizes[INPUT][0].width, 3); - coi = 0; cvmat_allowed = true; - if( cn > 1 ) - { - coi = cvtest::randInt(rng) % cn; - cvmat_allowed = false; - } } @@ -156,13 +140,6 @@ double CV_MomentsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/ int CV_MomentsTest::prepare_test_case( int test_case_idx ) { int code = cvtest::ArrayTest::prepare_test_case( test_case_idx ); - if( code > 0 ) - { - int cn = test_mat[INPUT][0].channels(); - if( cn > 1 ) - cvSetImageCOI( (IplImage*)test_array[INPUT][0], coi + 1 ); - } - return code; } @@ -171,7 +148,7 @@ void CV_MomentsTest::run_func() { CvMoments* m = (CvMoments*)test_mat[OUTPUT][0].ptr(); double* others = (double*)(m + 1); - if( try_umat ) + if (try_umat_) { UMat u; test_mat[INPUT][0].clone().copyTo(u); @@ -212,6 +189,7 @@ void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ ) memset( &m, 0, sizeof(m)); + int coi = 0; for( y = 0; y < src.rows; y++ ) { double s0 = 0, s1 = 0, s2 = 0, s3 = 0; @@ -431,7 +409,8 @@ void CV_HuMomentsTest::prepare_to_validation( int /*test_case_idx*/ ) } -TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test; test.safe_run(); } +TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test(false); test.safe_run(); } +OCL_TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test(true); test.safe_run(); } TEST(Imgproc_HuMoments, accuracy) { CV_HuMomentsTest test; test.safe_run(); } class CV_SmallContourMomentTest : public cvtest::BaseTest