CLAHE Python bindings
[profile/ivi/opencv.git] / modules / ocl / test / test_moments.cpp
1 #include "precomp.hpp"
2 #include <iomanip>
3 #include "opencv2/imgproc/imgproc_c.h"
4
5 #ifdef HAVE_OPENCL
6
7 using namespace cv;
8 using namespace cv::ocl;
9 using namespace cvtest;
10 using namespace testing;
11 using namespace std;
12 extern string workdir;
13 PARAM_TEST_CASE(MomentsTest, MatType, bool)
14 {
15     int type;
16     cv::Mat mat1;
17     bool test_contours;
18
19     virtual void SetUp()
20     {
21         type = GET_PARAM(0);
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);
26     }
27
28     void Compare(Moments& cpu, Moments& gpu)
29     {
30         Mat gpu_dst, cpu_dst;
31         HuMoments(cpu, cpu_dst);
32         HuMoments(gpu, gpu_dst);
33         EXPECT_MAT_NEAR(gpu_dst,cpu_dst, .5);
34     }
35
36 };
37
38
39 TEST_P(MomentsTest, Mat)
40 {
41     bool binaryImage = 0;
42     SetUp();
43
44     for(int j = 0; j < LOOP_TIMES; j++)
45     {
46         if(test_contours)
47         {
48             Mat src = imread( workdir + "../cpp/pic3.png", 1 );
49             Mat src_gray, canny_output;
50             cvtColor( src, src_gray, CV_BGR2GRAY );
51             vector<vector<Point> > contours;
52             vector<Vec4i> hierarchy;
53             Canny( src_gray, 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++ )
56             {
57                 Moments m = moments( contours[i], false );
58                 Moments dm = ocl::ocl_moments( contours[i], false );
59                 Compare(m, dm);
60             }
61         }
62         cv::_InputArray _array(mat1);
63         cv::Moments CvMom = cv::moments(_array, binaryImage);
64         cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
65
66         Compare(CvMom, oclMom);
67
68     }
69 }
70 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
71                             Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false)));
72 #endif // HAVE_OPENCL