Skip to content

Commit 942672a

Browse files
committed
Merge pull request opencv#9995 from alalek:ocl_fix_moments_9990
2 parents 9cceccd + 47ae519 commit 942672a

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

modules/imgproc/src/moments.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ static bool ocl_moments( InputArray _src, Moments& m, bool binary)
510510
int ntiles = xtiles*ytiles;
511511
UMat umbuf(1, ntiles*K, CV_32S);
512512

513-
size_t globalsize[] = {(size_t)xtiles, (size_t)sz.height}, localsize[] = {1, TILE_SIZE};
513+
size_t globalsize[] = {(size_t)xtiles, std::max((size_t)TILE_SIZE, (size_t)sz.height)};
514+
size_t localsize[] = {1, TILE_SIZE};
514515
bool ok = k.args(ocl::KernelArg::ReadOnly(src),
515516
ocl::KernelArg::PtrWriteOnly(umbuf),
516517
xtiles).run(2, globalsize, localsize, true);

modules/imgproc/test/test_moments.cpp

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
//
4040
//M*/
4141
#include "test_precomp.hpp"
42+
#include "opencv2/ts/ocl_test.hpp"
4243

4344
using namespace cv;
4445
using namespace std;
@@ -54,7 +55,7 @@ using namespace std;
5455
class CV_MomentsTest : public cvtest::ArrayTest
5556
{
5657
public:
57-
CV_MomentsTest();
58+
CV_MomentsTest(bool try_umat);
5859

5960
protected:
6061

@@ -65,18 +66,17 @@ class CV_MomentsTest : public cvtest::ArrayTest
6566
void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
6667
double get_success_error_level( int test_case_idx, int i, int j );
6768
void run_func();
68-
int coi;
6969
bool is_binary;
70-
bool try_umat;
70+
bool try_umat_;
7171
};
7272

7373

74-
CV_MomentsTest::CV_MomentsTest()
74+
CV_MomentsTest::CV_MomentsTest(bool try_umat) :
75+
try_umat_(try_umat)
7576
{
7677
test_array[INPUT].push_back(NULL);
7778
test_array[OUTPUT].push_back(NULL);
7879
test_array[REF_OUTPUT].push_back(NULL);
79-
coi = -1;
8080
is_binary = false;
8181
OCL_TUNING_MODE_ONLY(test_case_count = 10);
8282
//element_wise_relative_error = false;
@@ -110,40 +110,24 @@ void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx,
110110
{
111111
RNG& rng = ts->get_rng();
112112
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
113-
int cn = (cvtest::randInt(rng) % 4) + 1;
114113
int depth = cvtest::randInt(rng) % 4;
115114
depth = depth == 0 ? CV_8U : depth == 1 ? CV_16U : depth == 2 ? CV_16S : CV_32F;
116115

117116
is_binary = cvtest::randInt(rng) % 2 != 0;
118-
if( depth == 0 && !is_binary )
119-
try_umat = cvtest::randInt(rng) % 5 != 0;
120-
else
121-
try_umat = cvtest::randInt(rng) % 2 != 0;
122-
123-
if( cn == 2 || try_umat )
124-
cn = 1;
125117

126118
OCL_TUNING_MODE_ONLY(
127-
cn = 1;
128119
depth = CV_8U;
129-
try_umat = true;
130120
is_binary = false;
131121
sizes[INPUT][0] = Size(1024,768)
132122
);
133123

134-
types[INPUT][0] = CV_MAKETYPE(depth, cn);
124+
types[INPUT][0] = CV_MAKETYPE(depth, 1);
135125
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
136126
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(MOMENT_COUNT,1);
137127
if(CV_MAT_DEPTH(types[INPUT][0])>=CV_32S)
138128
sizes[INPUT][0].width = MAX(sizes[INPUT][0].width, 3);
139129

140-
coi = 0;
141130
cvmat_allowed = true;
142-
if( cn > 1 )
143-
{
144-
coi = cvtest::randInt(rng) % cn;
145-
cvmat_allowed = false;
146-
}
147131
}
148132

149133

@@ -156,13 +140,6 @@ double CV_MomentsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/
156140
int CV_MomentsTest::prepare_test_case( int test_case_idx )
157141
{
158142
int code = cvtest::ArrayTest::prepare_test_case( test_case_idx );
159-
if( code > 0 )
160-
{
161-
int cn = test_mat[INPUT][0].channels();
162-
if( cn > 1 )
163-
cvSetImageCOI( (IplImage*)test_array[INPUT][0], coi + 1 );
164-
}
165-
166143
return code;
167144
}
168145

@@ -171,7 +148,7 @@ void CV_MomentsTest::run_func()
171148
{
172149
CvMoments* m = (CvMoments*)test_mat[OUTPUT][0].ptr<double>();
173150
double* others = (double*)(m + 1);
174-
if( try_umat )
151+
if (try_umat_)
175152
{
176153
UMat u;
177154
test_mat[INPUT][0].clone().copyTo(u);
@@ -212,6 +189,7 @@ void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ )
212189

213190
memset( &m, 0, sizeof(m));
214191

192+
int coi = 0;
215193
for( y = 0; y < src.rows; y++ )
216194
{
217195
double s0 = 0, s1 = 0, s2 = 0, s3 = 0;
@@ -431,7 +409,8 @@ void CV_HuMomentsTest::prepare_to_validation( int /*test_case_idx*/ )
431409
}
432410

433411

434-
TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test; test.safe_run(); }
412+
TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test(false); test.safe_run(); }
413+
OCL_TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test(true); test.safe_run(); }
435414
TEST(Imgproc_HuMoments, accuracy) { CV_HuMomentsTest test; test.safe_run(); }
436415

437416
class CV_SmallContourMomentTest : public cvtest::BaseTest

0 commit comments

Comments
 (0)