1 /*M///////////////////////////////////////////////////////////////////////////////////////
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) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #include "perf_precomp.hpp"
46 using namespace testing;
49 //////////////////////////////////////////////////////////////////////
52 typedef std::tr1::tuple<string, string> pair_string;
53 DEF_PARAM_TEST_1(ImagePair, pair_string);
55 PERF_TEST_P(ImagePair, StereoBM,
56 Values(pair_string("gpu/perf/aloe.png", "gpu/perf/aloeR.png")))
60 const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE);
61 ASSERT_FALSE(imgLeft.empty());
63 const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE);
64 ASSERT_FALSE(imgRight.empty());
66 const int ndisp = 256;
70 cv::Ptr<cv::StereoBM> d_bm = cv::cuda::createStereoBM(ndisp);
72 const cv::cuda::GpuMat d_imgLeft(imgLeft);
73 const cv::cuda::GpuMat d_imgRight(imgRight);
76 TEST_CYCLE() d_bm->compute(d_imgLeft, d_imgRight, dst);
78 CUDA_SANITY_CHECK(dst);
82 cv::Ptr<cv::StereoBM> bm = cv::cuda::createStereoBM(ndisp);
86 TEST_CYCLE() bm->compute(imgLeft, imgRight, dst);
88 CPU_SANITY_CHECK(dst);
92 //////////////////////////////////////////////////////////////////////
93 // StereoBeliefPropagation
95 PERF_TEST_P(ImagePair, StereoBeliefPropagation,
96 Values(pair_string("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png")))
100 const cv::Mat imgLeft = readImage(GET_PARAM(0));
101 ASSERT_FALSE(imgLeft.empty());
103 const cv::Mat imgRight = readImage(GET_PARAM(1));
104 ASSERT_FALSE(imgRight.empty());
106 const int ndisp = 64;
110 cv::Ptr<cv::cuda::StereoBeliefPropagation> d_bp = cv::cuda::createStereoBeliefPropagation(ndisp);
112 const cv::cuda::GpuMat d_imgLeft(imgLeft);
113 const cv::cuda::GpuMat d_imgRight(imgRight);
114 cv::cuda::GpuMat dst;
116 TEST_CYCLE() d_bp->compute(d_imgLeft, d_imgRight, dst);
118 CUDA_SANITY_CHECK(dst);
126 //////////////////////////////////////////////////////////////////////
127 // StereoConstantSpaceBP
129 PERF_TEST_P(ImagePair, StereoConstantSpaceBP,
130 Values(pair_string("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-R.png")))
134 const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE);
135 ASSERT_FALSE(imgLeft.empty());
137 const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE);
138 ASSERT_FALSE(imgRight.empty());
140 const int ndisp = 128;
144 cv::Ptr<cv::cuda::StereoConstantSpaceBP> d_csbp = cv::cuda::createStereoConstantSpaceBP(ndisp);
146 const cv::cuda::GpuMat d_imgLeft(imgLeft);
147 const cv::cuda::GpuMat d_imgRight(imgRight);
148 cv::cuda::GpuMat dst;
150 TEST_CYCLE() d_csbp->compute(d_imgLeft, d_imgRight, dst);
152 CUDA_SANITY_CHECK(dst);
160 //////////////////////////////////////////////////////////////////////
161 // DisparityBilateralFilter
163 PERF_TEST_P(ImagePair, DisparityBilateralFilter,
164 Values(pair_string("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-disp.png")))
166 const cv::Mat img = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE);
167 ASSERT_FALSE(img.empty());
169 const cv::Mat disp = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE);
170 ASSERT_FALSE(disp.empty());
172 const int ndisp = 128;
176 cv::Ptr<cv::cuda::DisparityBilateralFilter> d_filter = cv::cuda::createDisparityBilateralFilter(ndisp);
178 const cv::cuda::GpuMat d_img(img);
179 const cv::cuda::GpuMat d_disp(disp);
180 cv::cuda::GpuMat dst;
182 TEST_CYCLE() d_filter->apply(d_disp, d_img, dst);
184 CUDA_SANITY_CHECK(dst);
192 //////////////////////////////////////////////////////////////////////
193 // ReprojectImageTo3D
195 PERF_TEST_P(Sz_Depth, ReprojectImageTo3D,
196 Combine(CUDA_TYPICAL_MAT_SIZES,
197 Values(CV_8U, CV_16S)))
199 const cv::Size size = GET_PARAM(0);
200 const int depth = GET_PARAM(1);
202 cv::Mat src(size, depth);
203 declare.in(src, WARMUP_RNG);
205 cv::Mat Q(4, 4, CV_32FC1);
206 cv::randu(Q, 0.1, 1.0);
210 const cv::cuda::GpuMat d_src(src);
211 cv::cuda::GpuMat dst;
213 TEST_CYCLE() cv::cuda::reprojectImageTo3D(d_src, dst, Q);
215 CUDA_SANITY_CHECK(dst);
221 TEST_CYCLE() cv::reprojectImageTo3D(src, dst, Q);
223 CPU_SANITY_CHECK(dst);
227 //////////////////////////////////////////////////////////////////////
230 PERF_TEST_P(Sz_Depth, DrawColorDisp,
231 Combine(CUDA_TYPICAL_MAT_SIZES,
232 Values(CV_8U, CV_16S)))
234 const cv::Size size = GET_PARAM(0);
235 const int type = GET_PARAM(1);
237 cv::Mat src(size, type);
238 declare.in(src, WARMUP_RNG);
242 const cv::cuda::GpuMat d_src(src);
243 cv::cuda::GpuMat dst;
245 TEST_CYCLE() cv::cuda::drawColorDisp(d_src, dst, 255);
247 CUDA_SANITY_CHECK(dst);