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;
13 PARAM_TEST_CASE(MomentsTest, MatType, bool)
22 test_contours = GET_PARAM(1);
23 cv::Size size(10*MWIDTH, 10*MHEIGHT);
24 mat1 = randomMat(size, type, 5, 16, false);
27 void Compare(Moments& cpu, Moments& gpu)
30 HuMoments(cpu, cpu_dst);
31 HuMoments(gpu, gpu_dst);
32 EXPECT_MAT_NEAR(gpu_dst,cpu_dst, .5);
38 OCL_TEST_P(MomentsTest, Mat)
42 for(int j = 0; j < LOOP_TIMES; j++)
46 Mat src = readImage( "cv/shared/pic3.png", IMREAD_GRAYSCALE );
47 ASSERT_FALSE(src.empty());
49 vector<vector<Point> > contours;
50 vector<Vec4i> hierarchy;
51 Canny( src, canny_output, 100, 200, 3 );
52 findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
53 for( size_t i = 0; i < contours.size(); i++ )
55 Moments m = moments( contours[i], false );
56 Moments dm = ocl::ocl_moments( contours[i], false );
60 cv::_InputArray _array(mat1);
61 cv::Moments CvMom = cv::moments(_array, binaryImage);
62 cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
64 Compare(CvMom, oclMom);
68 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
69 Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false)));