CLAHE Python bindings
[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 "precomp.hpp"
47 #include <iomanip>
48
49 #ifdef HAVE_OPENCL
50
51 using namespace cv;
52
53 extern std::string workdir;
54 PARAM_TEST_CASE(StereoMatchBM, int, int)
55 {
56     int n_disp;
57     int winSize;
58
59     virtual void SetUp()
60     {
61         n_disp  = GET_PARAM(0);
62         winSize = GET_PARAM(1);
63     }
64 };
65
66 TEST_P(StereoMatchBM, Regression)
67 {
68
69     Mat left_image  = readImage("stereobm/aloe-L.png", IMREAD_GRAYSCALE);
70     Mat right_image = readImage("stereobm/aloe-R.png", IMREAD_GRAYSCALE);
71     Mat disp_gold   = readImage("stereobm/aloe-disp.png", IMREAD_GRAYSCALE);
72     ocl::oclMat d_left, d_right;
73     ocl::oclMat d_disp(left_image.size(), CV_8U);
74     Mat  disp;
75
76     ASSERT_FALSE(left_image.empty());
77     ASSERT_FALSE(right_image.empty());
78     ASSERT_FALSE(disp_gold.empty());
79     d_left.upload(left_image);
80     d_right.upload(right_image);
81
82     ocl::StereoBM_OCL bm(0, n_disp, winSize);
83
84
85     bm(d_left, d_right, d_disp);
86     d_disp.download(disp);
87
88     EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-3);
89 }
90
91 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchBM, testing::Combine(testing::Values(128),
92                                        testing::Values(19)));
93
94 PARAM_TEST_CASE(StereoMatchBP, int, int, int, float, float, float, float)
95 {
96     int ndisp_;
97     int iters_;
98     int levels_;
99     float max_data_term_;
100     float data_weight_;
101     float max_disc_term_;
102     float disc_single_jump_;
103     virtual void SetUp()
104     {
105         ndisp_          = GET_PARAM(0);
106         iters_          = GET_PARAM(1);
107         levels_         = GET_PARAM(2);
108         max_data_term_  = GET_PARAM(3);
109         data_weight_    = GET_PARAM(4);
110         max_disc_term_     = GET_PARAM(5);
111         disc_single_jump_  = GET_PARAM(6);
112     }
113 };
114 TEST_P(StereoMatchBP, Regression)
115 {
116     Mat left_image  = readImage("stereobp/aloe-L.png");
117     Mat right_image = readImage("stereobp/aloe-R.png");
118     Mat disp_gold   = readImage("stereobp/aloe-disp.png", IMREAD_GRAYSCALE);
119     ocl::oclMat d_left, d_right;
120     ocl::oclMat d_disp;
121     Mat  disp;
122     ASSERT_FALSE(left_image.empty());
123     ASSERT_FALSE(right_image.empty());
124     ASSERT_FALSE(disp_gold.empty());
125     d_left.upload(left_image);
126     d_right.upload(right_image);
127     ocl::StereoBeliefPropagation bp(ndisp_, iters_, levels_, max_data_term_, data_weight_,
128         max_disc_term_, disc_single_jump_, CV_16S);
129     bp(d_left, d_right, d_disp);
130     d_disp.download(disp);
131     disp.convertTo(disp, disp_gold.depth());
132     EXPECT_MAT_NEAR(disp_gold, disp, 0.0);
133 }
134 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchBP, testing::Combine(testing::Values(64),
135     testing::Values(8),testing::Values(2),testing::Values(25.0f),
136     testing::Values(0.1f),testing::Values(15.0f),testing::Values(1.0f)));
137
138 //////////////////////////////////////////////////////////////////////////
139 //  ConstSpaceBeliefPropagation
140 PARAM_TEST_CASE(StereoMatchConstSpaceBP, int, int, int, int, float, float, float, float, int, int)
141 {
142     int ndisp_;
143     int iters_;
144     int levels_;
145     int nr_plane_;
146     float max_data_term_;
147     float data_weight_;
148     float max_disc_term_;
149     float disc_single_jump_;
150     int min_disp_th_;
151     int msg_type_;
152
153     virtual void SetUp()
154     {
155         ndisp_          = GET_PARAM(0);
156         iters_          = GET_PARAM(1);
157         levels_         = GET_PARAM(2);
158         nr_plane_ = GET_PARAM(3);
159         max_data_term_  = GET_PARAM(4);
160         data_weight_    = GET_PARAM(5);
161         max_disc_term_     = GET_PARAM(6);
162         disc_single_jump_  = GET_PARAM(7);
163         min_disp_th_ = GET_PARAM(8);
164         msg_type_  = GET_PARAM(9);
165     }
166 };
167 TEST_P(StereoMatchConstSpaceBP, Regression)
168 {
169     Mat left_image  = readImage("csstereobp/aloe-L.png");
170     Mat right_image = readImage("csstereobp/aloe-R.png");
171     Mat disp_gold   = readImage("csstereobp/aloe-disp.png", IMREAD_GRAYSCALE);
172
173     ocl::oclMat d_left, d_right;
174     ocl::oclMat d_disp;
175
176     Mat  disp;
177     ASSERT_FALSE(left_image.empty());
178     ASSERT_FALSE(right_image.empty());
179     ASSERT_FALSE(disp_gold.empty());
180
181     d_left.upload(left_image);
182     d_right.upload(right_image);
183
184     ocl::StereoConstantSpaceBP bp(ndisp_, iters_, levels_, nr_plane_, max_data_term_, data_weight_,
185         max_disc_term_, disc_single_jump_, 0, CV_32F);
186     bp(d_left, d_right, d_disp);
187     d_disp.download(disp);
188     disp.convertTo(disp, disp_gold.depth());
189
190     EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-4);
191     //EXPECT_MAT_NEAR(disp_gold, disp, 1.0, "");
192 }
193 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchConstSpaceBP, testing::Combine(testing::Values(128),
194     testing::Values(16),testing::Values(4), testing::Values(4), testing::Values(30.0f),
195     testing::Values(1.0f),testing::Values(160.0f),
196     testing::Values(10.0f), testing::Values(0), testing::Values(CV_32F)));
197 #endif // HAVE_OPENCL