1 #include "test_precomp.hpp"
3 #include "opencv2/imgproc/imgproc_c.h"
8 using namespace cv::ocl;
9 using namespace cvtest;
10 using namespace testing;
12 extern string workdir;
13 PARAM_TEST_CASE(MomentsTest, MatType, bool)
22 test_contours = GET_PARAM(1);
23 cv::RNG &rng = TS::ptr()->get_rng();
24 cv::Size size(10*MWIDTH, 10*MHEIGHT);
25 mat1 = randomMat(rng, size, type, 5, 16, false);
28 void Compare(Moments& cpu, Moments& gpu)
31 HuMoments(cpu, cpu_dst);
32 HuMoments(gpu, gpu_dst);
33 EXPECT_MAT_NEAR(gpu_dst,cpu_dst, .5);
39 TEST_P(MomentsTest, Mat)
44 for(int j = 0; j < LOOP_TIMES; j++)
48 Mat src = readImage( "cv/shared/pic3.png", IMREAD_GRAYSCALE );
49 ASSERT_FALSE(src.empty());
51 vector<vector<Point> > contours;
52 vector<Vec4i> hierarchy;
53 Canny( src, canny_output, 100, 200, 3 );
54 findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
55 for( size_t i = 0; i < contours.size(); i++ )
57 Moments m = moments( contours[i], false );
58 Moments dm = ocl::ocl_moments( contours[i], false );
62 cv::_InputArray _array(mat1);
63 cv::Moments CvMom = cv::moments(_array, binaryImage);
64 cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
66 Compare(CvMom, oclMom);
70 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
71 Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false)));