mirror of
https://github.com/opencv/opencv.git
synced 2025-08-05 22:19:14 +08:00
Merge pull request #9995 from alalek:ocl_fix_moments_9990
This commit is contained in:
commit
942672ad91
@ -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);
|
||||
|
@ -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>();
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user