perf_histogram.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. // HistEvenC1
  46. DEF_PARAM_TEST(Sz_Depth, cv::Size, MatDepth);
  47. PERF_TEST_P(Sz_Depth, HistEvenC1,
  48. Combine(CUDA_TYPICAL_MAT_SIZES,
  49. Values(CV_8U, CV_16U, CV_16S)))
  50. {
  51. const cv::Size size = GET_PARAM(0);
  52. const int depth = GET_PARAM(1);
  53. cv::Mat src(size, depth);
  54. declare.in(src, WARMUP_RNG);
  55. if (PERF_RUN_CUDA())
  56. {
  57. const cv::cuda::GpuMat d_src(src);
  58. cv::cuda::GpuMat dst;
  59. TEST_CYCLE() cv::cuda::histEven(d_src, dst, 30, 0, 180);
  60. CUDA_SANITY_CHECK(dst);
  61. }
  62. else
  63. {
  64. const int hbins = 30;
  65. const float hranges[] = {0.0f, 180.0f};
  66. const int histSize[] = {hbins};
  67. const float* ranges[] = {hranges};
  68. const int channels[] = {0};
  69. cv::Mat dst;
  70. TEST_CYCLE() cv::calcHist(&src, 1, channels, cv::Mat(), dst, 1, histSize, ranges);
  71. CPU_SANITY_CHECK(dst);
  72. }
  73. }
  74. //////////////////////////////////////////////////////////////////////
  75. // HistEvenC4
  76. PERF_TEST_P(Sz_Depth, HistEvenC4,
  77. Combine(CUDA_TYPICAL_MAT_SIZES,
  78. Values(CV_8U, CV_16U, CV_16S)))
  79. {
  80. const cv::Size size = GET_PARAM(0);
  81. const int depth = GET_PARAM(1);
  82. cv::Mat src(size, CV_MAKE_TYPE(depth, 4));
  83. declare.in(src, WARMUP_RNG);
  84. int histSize[] = {30, 30, 30, 30};
  85. int lowerLevel[] = {0, 0, 0, 0};
  86. int upperLevel[] = {180, 180, 180, 180};
  87. if (PERF_RUN_CUDA())
  88. {
  89. const cv::cuda::GpuMat d_src(src);
  90. cv::cuda::GpuMat d_hist[4];
  91. TEST_CYCLE() cv::cuda::histEven(d_src, d_hist, histSize, lowerLevel, upperLevel);
  92. cv::Mat cpu_hist0, cpu_hist1, cpu_hist2, cpu_hist3;
  93. d_hist[0].download(cpu_hist0);
  94. d_hist[1].download(cpu_hist1);
  95. d_hist[2].download(cpu_hist2);
  96. d_hist[3].download(cpu_hist3);
  97. SANITY_CHECK(cpu_hist0);
  98. SANITY_CHECK(cpu_hist1);
  99. SANITY_CHECK(cpu_hist2);
  100. SANITY_CHECK(cpu_hist3);
  101. }
  102. else
  103. {
  104. FAIL_NO_CPU();
  105. }
  106. }
  107. //////////////////////////////////////////////////////////////////////
  108. // CalcHist
  109. PERF_TEST_P(Sz, CalcHist,
  110. CUDA_TYPICAL_MAT_SIZES)
  111. {
  112. const cv::Size size = GetParam();
  113. cv::Mat src(size, CV_8UC1);
  114. declare.in(src, WARMUP_RNG);
  115. if (PERF_RUN_CUDA())
  116. {
  117. const cv::cuda::GpuMat d_src(src);
  118. cv::cuda::GpuMat dst;
  119. TEST_CYCLE() cv::cuda::calcHist(d_src, dst);
  120. CUDA_SANITY_CHECK(dst);
  121. }
  122. else
  123. {
  124. FAIL_NO_CPU();
  125. }
  126. }
  127. //////////////////////////////////////////////////////////////////////
  128. // EqualizeHist
  129. PERF_TEST_P(Sz, EqualizeHist,
  130. CUDA_TYPICAL_MAT_SIZES)
  131. {
  132. const cv::Size size = GetParam();
  133. cv::Mat src(size, CV_8UC1);
  134. declare.in(src, WARMUP_RNG);
  135. if (PERF_RUN_CUDA())
  136. {
  137. const cv::cuda::GpuMat d_src(src);
  138. cv::cuda::GpuMat dst;
  139. TEST_CYCLE() cv::cuda::equalizeHist(d_src, dst);
  140. CUDA_SANITY_CHECK(dst);
  141. }
  142. else
  143. {
  144. cv::Mat dst;
  145. TEST_CYCLE() cv::equalizeHist(src, dst);
  146. CPU_SANITY_CHECK(dst);
  147. }
  148. }
  149. //////////////////////////////////////////////////////////////////////
  150. // CLAHE
  151. DEF_PARAM_TEST(Sz_ClipLimit, cv::Size, double, MatType);
  152. PERF_TEST_P(Sz_ClipLimit, CLAHE,
  153. Combine(CUDA_TYPICAL_MAT_SIZES,
  154. Values(0.0, 40.0),
  155. Values(MatType(CV_8UC1), MatType(CV_16UC1))))
  156. {
  157. const cv::Size size = GET_PARAM(0);
  158. const double clipLimit = GET_PARAM(1);
  159. const int type = GET_PARAM(2);
  160. cv::Mat src(size, type);
  161. declare.in(src, WARMUP_RNG);
  162. if (PERF_RUN_CUDA())
  163. {
  164. cv::Ptr<cv::cuda::CLAHE> clahe = cv::cuda::createCLAHE(clipLimit);
  165. cv::cuda::GpuMat d_src(src);
  166. cv::cuda::GpuMat dst;
  167. TEST_CYCLE() clahe->apply(d_src, dst);
  168. CUDA_SANITY_CHECK(dst);
  169. }
  170. else
  171. {
  172. cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
  173. cv::Mat dst;
  174. TEST_CYCLE() clahe->apply(src, dst);
  175. CPU_SANITY_CHECK(dst);
  176. }
  177. }
  178. }} // namespace