catching OpenCL double not supported exceptions
[profile/ivi/opencv.git] / modules / ocl / test / test_moments.cpp
1 #include "test_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
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::Size size(10*MWIDTH, 10*MHEIGHT);
24         mat1 = randomMat(size, type, 5, 16, false);
25     }
26
27     void Compare(Moments& cpu, Moments& gpu)
28     {
29         Mat gpu_dst, cpu_dst;
30         HuMoments(cpu, cpu_dst);
31         HuMoments(gpu, gpu_dst);
32         EXPECT_MAT_NEAR(gpu_dst,cpu_dst, .5);
33     }
34
35 };
36
37
38 OCL_TEST_P(MomentsTest, Mat)
39 {
40     bool binaryImage = 0;
41
42     for(int j = 0; j < LOOP_TIMES; j++)
43     {
44         if(test_contours)
45         {
46             Mat src = readImage( "cv/shared/pic3.png", IMREAD_GRAYSCALE );
47             ASSERT_FALSE(src.empty());
48             Mat canny_output;
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++ )
54             {
55                 Moments m = moments( contours[i], false );
56                 Moments dm = ocl::ocl_moments( contours[i], false );
57                 Compare(m, dm);
58             }
59         }
60         cv::_InputArray _array(mat1);
61         cv::Moments CvMom = cv::moments(_array, binaryImage);
62         cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
63
64         Compare(CvMom, oclMom);
65
66     }
67 }
68 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
69                             Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false)));
70 #endif // HAVE_OPENCL