1 ///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
18 // Peng Xiao, pengxiao@outlook.com
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
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.
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.
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.
46 #include "precomp.hpp"
53 extern std::string workdir;
54 PARAM_TEST_CASE(StereoMatchBM, int, int)
61 n_disp = GET_PARAM(0);
62 winSize = GET_PARAM(1);
66 TEST_P(StereoMatchBM, Regression)
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);
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);
82 ocl::StereoBM_OCL bm(0, n_disp, winSize);
85 bm(d_left, d_right, d_disp);
86 d_disp.download(disp);
88 EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-3);
91 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchBM, testing::Combine(testing::Values(128),
92 testing::Values(19)));
94 PARAM_TEST_CASE(StereoMatchBP, int, int, int, float, float, float, float)
101 float max_disc_term_;
102 float disc_single_jump_;
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);
114 TEST_P(StereoMatchBP, Regression)
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;
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);
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)));
138 //////////////////////////////////////////////////////////////////////////
139 // ConstSpaceBeliefPropagation
140 PARAM_TEST_CASE(StereoMatchConstSpaceBP, int, int, int, int, float, float, float, float, int, int)
146 float max_data_term_;
148 float max_disc_term_;
149 float disc_single_jump_;
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);
167 TEST_P(StereoMatchConstSpaceBP, Regression)
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);
173 ocl::oclMat d_left, d_right;
177 ASSERT_FALSE(left_image.empty());
178 ASSERT_FALSE(right_image.empty());
179 ASSERT_FALSE(disp_gold.empty());
181 d_left.upload(left_image);
182 d_right.upload(right_image);
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());
190 EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-4);
191 //EXPECT_MAT_NEAR(disp_gold, disp, 1.0, "");
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