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 "test_precomp.hpp"
53 PARAM_TEST_CASE(StereoMatchBM, int, int)
60 n_disp = GET_PARAM(0);
61 winSize = GET_PARAM(1);
65 TEST_P(StereoMatchBM, Regression)
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);
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);
81 ocl::StereoBM_OCL bm(0, n_disp, winSize);
84 bm(d_left, d_right, d_disp);
85 d_disp.download(disp);
87 EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-3);
90 INSTANTIATE_TEST_CASE_P(OCL_Calib3D, StereoMatchBM, testing::Combine(testing::Values(128),
91 testing::Values(19)));
93 PARAM_TEST_CASE(StereoMatchBP, int, int, int, float, float, float, float)
100 float max_disc_term_;
101 float disc_single_jump_;
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);
113 TEST_P(StereoMatchBP, Regression)
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;
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);
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)));
137 //////////////////////////////////////////////////////////////////////////
138 // ConstSpaceBeliefPropagation
139 PARAM_TEST_CASE(StereoMatchConstSpaceBP, int, int, int, int, float, float, float, float, int, int)
145 float max_data_term_;
147 float max_disc_term_;
148 float disc_single_jump_;
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);
166 TEST_P(StereoMatchConstSpaceBP, Regression)
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);
172 ocl::oclMat d_left, d_right;
176 ASSERT_FALSE(left_image.empty());
177 ASSERT_FALSE(right_image.empty());
178 ASSERT_FALSE(disp_gold.empty());
180 d_left.upload(left_image);
181 d_right.upload(right_image);
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());
189 EXPECT_MAT_SIMILAR(disp_gold, disp, 1e-4);
190 //EXPECT_MAT_NEAR(disp_gold, disp, 1.0, "");
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