perf_stereo.cpp 9.1 KB

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