1 /*M/////////////////////////////////////////////////////////////////////////////////////// 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) 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. 16 // 17 // Redistribution and use in source and binary forms, with or without modification, 18 // are permitted provided that the following conditions are met: 19 // 20 // * Redistribution's of source code must retain the above copyright notice, 21 // this list of conditions and the following disclaimer. 22 // 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. 26 // 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. 29 // 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. 40 // 41 //M*/ 42 43 #include "perf_precomp.hpp" 44 45 using namespace std; 46 using namespace testing; 47 using namespace perf; 48 49 ////////////////////////////////////////////////////////////////////// 50 // StereoBM 51 52 typedef std::tr1::tuple<string, string> pair_string; 53 DEF_PARAM_TEST_1(ImagePair, pair_string); 54 55 PERF_TEST_P(ImagePair, StereoBM, 56 Values(pair_string("gpu/perf/aloe.png", "gpu/perf/aloeR.png"))) 57 { 58 declare.time(300.0); 59 60 const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE); 61 ASSERT_FALSE(imgLeft.empty()); 62 63 const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); 64 ASSERT_FALSE(imgRight.empty()); 65 66 const int ndisp = 256; 67 68 if (PERF_RUN_CUDA()) 69 { 70 cv::Ptr<cv::StereoBM> d_bm = cv::cuda::createStereoBM(ndisp); 71 72 const cv::cuda::GpuMat d_imgLeft(imgLeft); 73 const cv::cuda::GpuMat d_imgRight(imgRight); 74 cv::cuda::GpuMat dst; 75 76 TEST_CYCLE() d_bm->compute(d_imgLeft, d_imgRight, dst); 77 78 CUDA_SANITY_CHECK(dst); 79 } 80 else 81 { 82 cv::Ptr<cv::StereoBM> bm = cv::StereoBM::create(ndisp); 83 84 cv::Mat dst; 85 86 TEST_CYCLE() bm->compute(imgLeft, imgRight, dst); 87 88 CPU_SANITY_CHECK(dst); 89 } 90 } 91 92 ////////////////////////////////////////////////////////////////////// 93 // StereoBeliefPropagation 94 95 PERF_TEST_P(ImagePair, StereoBeliefPropagation, 96 Values(pair_string("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png"))) 97 { 98 declare.time(300.0); 99 100 const cv::Mat imgLeft = readImage(GET_PARAM(0)); 101 ASSERT_FALSE(imgLeft.empty()); 102 103 const cv::Mat imgRight = readImage(GET_PARAM(1)); 104 ASSERT_FALSE(imgRight.empty()); 105 106 const int ndisp = 64; 107 108 if (PERF_RUN_CUDA()) 109 { 110 cv::Ptr<cv::cuda::StereoBeliefPropagation> d_bp = cv::cuda::createStereoBeliefPropagation(ndisp); 111 112 const cv::cuda::GpuMat d_imgLeft(imgLeft); 113 const cv::cuda::GpuMat d_imgRight(imgRight); 114 cv::cuda::GpuMat dst; 115 116 TEST_CYCLE() d_bp->compute(d_imgLeft, d_imgRight, dst); 117 118 CUDA_SANITY_CHECK(dst); 119 } 120 else 121 { 122 FAIL_NO_CPU(); 123 } 124 } 125 126 ////////////////////////////////////////////////////////////////////// 127 // StereoConstantSpaceBP 128 129 PERF_TEST_P(ImagePair, StereoConstantSpaceBP, 130 Values(pair_string("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-R.png"))) 131 { 132 declare.time(300.0); 133 134 const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE); 135 ASSERT_FALSE(imgLeft.empty()); 136 137 const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); 138 ASSERT_FALSE(imgRight.empty()); 139 140 const int ndisp = 128; 141 142 if (PERF_RUN_CUDA()) 143 { 144 cv::Ptr<cv::cuda::StereoConstantSpaceBP> d_csbp = cv::cuda::createStereoConstantSpaceBP(ndisp); 145 146 const cv::cuda::GpuMat d_imgLeft(imgLeft); 147 const cv::cuda::GpuMat d_imgRight(imgRight); 148 cv::cuda::GpuMat dst; 149 150 TEST_CYCLE() d_csbp->compute(d_imgLeft, d_imgRight, dst); 151 152 CUDA_SANITY_CHECK(dst); 153 } 154 else 155 { 156 FAIL_NO_CPU(); 157 } 158 } 159 160 ////////////////////////////////////////////////////////////////////// 161 // DisparityBilateralFilter 162 163 PERF_TEST_P(ImagePair, DisparityBilateralFilter, 164 Values(pair_string("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-disp.png"))) 165 { 166 const cv::Mat img = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE); 167 ASSERT_FALSE(img.empty()); 168 169 const cv::Mat disp = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); 170 ASSERT_FALSE(disp.empty()); 171 172 const int ndisp = 128; 173 174 if (PERF_RUN_CUDA()) 175 { 176 cv::Ptr<cv::cuda::DisparityBilateralFilter> d_filter = cv::cuda::createDisparityBilateralFilter(ndisp); 177 178 const cv::cuda::GpuMat d_img(img); 179 const cv::cuda::GpuMat d_disp(disp); 180 cv::cuda::GpuMat dst; 181 182 TEST_CYCLE() d_filter->apply(d_disp, d_img, dst); 183 184 CUDA_SANITY_CHECK(dst); 185 } 186 else 187 { 188 FAIL_NO_CPU(); 189 } 190 } 191 192 ////////////////////////////////////////////////////////////////////// 193 // ReprojectImageTo3D 194 195 PERF_TEST_P(Sz_Depth, ReprojectImageTo3D, 196 Combine(CUDA_TYPICAL_MAT_SIZES, 197 Values(CV_8U, CV_16S))) 198 { 199 const cv::Size size = GET_PARAM(0); 200 const int depth = GET_PARAM(1); 201 202 cv::Mat src(size, depth); 203 declare.in(src, WARMUP_RNG); 204 205 cv::Mat Q(4, 4, CV_32FC1); 206 cv::randu(Q, 0.1, 1.0); 207 208 if (PERF_RUN_CUDA()) 209 { 210 const cv::cuda::GpuMat d_src(src); 211 cv::cuda::GpuMat dst; 212 213 TEST_CYCLE() cv::cuda::reprojectImageTo3D(d_src, dst, Q); 214 215 CUDA_SANITY_CHECK(dst); 216 } 217 else 218 { 219 cv::Mat dst; 220 221 TEST_CYCLE() cv::reprojectImageTo3D(src, dst, Q); 222 223 CPU_SANITY_CHECK(dst); 224 } 225 } 226 227 ////////////////////////////////////////////////////////////////////// 228 // DrawColorDisp 229 230 PERF_TEST_P(Sz_Depth, DrawColorDisp, 231 Combine(CUDA_TYPICAL_MAT_SIZES, 232 Values(CV_8U, CV_16S))) 233 { 234 const cv::Size size = GET_PARAM(0); 235 const int type = GET_PARAM(1); 236 237 cv::Mat src(size, type); 238 declare.in(src, WARMUP_RNG); 239 240 if (PERF_RUN_CUDA()) 241 { 242 const cv::cuda::GpuMat d_src(src); 243 cv::cuda::GpuMat dst; 244 245 TEST_CYCLE() cv::cuda::drawColorDisp(d_src, dst, 255); 246 247 CUDA_SANITY_CHECK(dst); 248 } 249 else 250 { 251 FAIL_NO_CPU(); 252 } 253 } 254