catching OpenCL double not supported exceptions
[profile/ivi/opencv.git] / modules / ocl / test / test_calib3d.cpp
1 ///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // @Authors
18 //     Peng Xiao, pengxiao@outlook.com
19 //
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
22 //
23 //   * Redistribution's of source code must retain the above copyright notice,
24 //     this list of conditions and the following disclaimer.
25 //
26 //   * Redistribution's in binary form must reproduce the above copyright notice,
27 //     this list of conditions and the following disclaimer in the documentation
28 //     and/or other oclMaterials provided with the distribution.
29 //
30 //   * The name of the copyright holders may not be used to endorse or promote products
31 //     derived from this software without specific prior written permission.
32 //
33 // This software is provided by the copyright holders and contributors "as is" and
34 // any express or implied warranties, including, but not limited to, the implied
35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
36 // In no event shall the Intel Corporation or contributors be liable for any direct,
37 // indirect, incidental, special, exemplary, or consequential damages
38 // (including, but not limited to, procurement of substitute goods or services;
39 // loss of use, data, or profits; or business interruption) however caused
40 // and on any theory of liability, whether in contract, strict liability,
41 // or tort (including negligence or otherwise) arising in any way out of
42 // the use of this software, even if advised of the possibility of such damage.
43 //
44 //M*/
45
46 #include "test_precomp.hpp"
47 #include <iomanip>
48
49 using namespace cv;
50
51 #ifdef HAVE_OPENCL
52
53 PARAM_TEST_CASE(StereoMatchBM, int, int)
54 {
55     int n_disp;
56     int winSize;
57
58     virtual void SetUp()
59     {
60         n_disp  = GET_PARAM(0);
61         winSize = GET_PARAM(1);
62     }
63 };
64
65 OCL_TEST_P(StereoMatchBM, Regression)
66 {
67
68     Mat left_image  = readImage("gpu/stereobm/aloe-L.png", IMREAD_GRAYSCALE);
69     Mat right_image = readImage("gpu/stereobm/aloe-R.png", IMREAD_GRAYSCALE);
70     Mat disp_gold   = readImage("gpu/stereobm/aloe-disp.png", IMREAD_GRAYSCALE);
71     ocl::oclMat d_left, d_right;
72     ocl::oclMat d_disp(left_image.size(), CV_8U);
73     Mat  disp;
74
75     ASSERT_FALSE(left_image.empty());
76     ASSERT_FALSE(right_image.empty());
77     ASSERT_FALSE(disp_gold.empty());
78     d_left.upload(left_image);
79     d_right.upload(right_image);
80
81     ocl::StereoBM_OCL bm(0, n_disp, winSize);
82
83
84     bm(d_left, d_right, d_disp);
85     d_disp.download(disp);
86
87     EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-3);
88 }
89
90 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchBM, testing::Combine(testing::Values(128),
91                                        testing::Values(19)));
92
93 PARAM_TEST_CASE(StereoMatchBP, int, int, int, float, float, float, float)
94 {
95     int ndisp_;
96     int iters_;
97     int levels_;
98     float max_data_term_;
99     float data_weight_;
100     float max_disc_term_;
101     float disc_single_jump_;
102     virtual void SetUp()
103     {
104         ndisp_          = GET_PARAM(0);
105         iters_          = GET_PARAM(1);
106         levels_         = GET_PARAM(2);
107         max_data_term_  = GET_PARAM(3);
108         data_weight_    = GET_PARAM(4);
109         max_disc_term_     = GET_PARAM(5);
110         disc_single_jump_  = GET_PARAM(6);
111     }
112 };
113 OCL_TEST_P(StereoMatchBP, Regression)
114 {
115     Mat left_image  = readImage("gpu/stereobp/aloe-L.png");
116     Mat right_image = readImage("gpu/stereobp/aloe-R.png");
117     Mat disp_gold   = readImage("gpu/stereobp/aloe-disp.png", IMREAD_GRAYSCALE);
118     ocl::oclMat d_left, d_right;
119     ocl::oclMat d_disp;
120     Mat  disp;
121     ASSERT_FALSE(left_image.empty());
122     ASSERT_FALSE(right_image.empty());
123     ASSERT_FALSE(disp_gold.empty());
124     d_left.upload(left_image);
125     d_right.upload(right_image);
126     ocl::StereoBeliefPropagation bp(ndisp_, iters_, levels_, max_data_term_, data_weight_,
127         max_disc_term_, disc_single_jump_, CV_16S);
128     bp(d_left, d_right, d_disp);
129     d_disp.download(disp);
130     disp.convertTo(disp, disp_gold.depth());
131     EXPECT_MAT_NEAR(disp_gold, disp, 0.0);
132 }
133 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchBP, testing::Combine(testing::Values(64),
134     testing::Values(8),testing::Values(2),testing::Values(25.0f),
135     testing::Values(0.1f),testing::Values(15.0f),testing::Values(1.0f)));
136
137 //////////////////////////////////////////////////////////////////////////
138 //  ConstSpaceBeliefPropagation
139 PARAM_TEST_CASE(StereoMatchConstSpaceBP, int, int, int, int, float, float, float, float, int, int)
140 {
141     int ndisp_;
142     int iters_;
143     int levels_;
144     int nr_plane_;
145     float max_data_term_;
146     float data_weight_;
147     float max_disc_term_;
148     float disc_single_jump_;
149     int min_disp_th_;
150     int msg_type_;
151
152     virtual void SetUp()
153     {
154         ndisp_          = GET_PARAM(0);
155         iters_          = GET_PARAM(1);
156         levels_         = GET_PARAM(2);
157         nr_plane_ = GET_PARAM(3);
158         max_data_term_  = GET_PARAM(4);
159         data_weight_    = GET_PARAM(5);
160         max_disc_term_     = GET_PARAM(6);
161         disc_single_jump_  = GET_PARAM(7);
162         min_disp_th_ = GET_PARAM(8);
163         msg_type_  = GET_PARAM(9);
164     }
165 };
166 OCL_TEST_P(StereoMatchConstSpaceBP, Regression)
167 {
168     Mat left_image  = readImage("gpu/csstereobp/aloe-L.png");
169     Mat right_image = readImage("gpu/csstereobp/aloe-R.png");
170     Mat disp_gold   = readImage("gpu/csstereobp/aloe-disp.png", IMREAD_GRAYSCALE);
171
172     ocl::oclMat d_left, d_right;
173     ocl::oclMat d_disp;
174
175     Mat  disp;
176     ASSERT_FALSE(left_image.empty());
177     ASSERT_FALSE(right_image.empty());
178     ASSERT_FALSE(disp_gold.empty());
179
180     d_left.upload(left_image);
181     d_right.upload(right_image);
182
183     ocl::StereoConstantSpaceBP bp(ndisp_, iters_, levels_, nr_plane_, max_data_term_, data_weight_,
184         max_disc_term_, disc_single_jump_, 0, CV_32F);
185     bp(d_left, d_right, d_disp);
186     d_disp.download(disp);
187     disp.convertTo(disp, disp_gold.depth());
188
189     EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-4);
190     //EXPECT_MAT_NEAR(disp_gold, disp, 1.0, "");
191 }
192 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchConstSpaceBP, testing::Combine(testing::Values(128),
193     testing::Values(16),testing::Values(4), testing::Values(4), testing::Values(30.0f),
194     testing::Values(1.0f),testing::Values(160.0f),
195     testing::Values(10.0f), testing::Values(0), testing::Values(CV_32F)));
196 #endif // HAVE_OPENCL