perf_blur.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "perf_precomp.hpp"
  5. namespace opencv_test {
  6. typedef tuple<Size, MatType, int> Size_MatType_kSize_t;
  7. typedef perf::TestBaseWithParam<Size_MatType_kSize_t> Size_MatType_kSize;
  8. PERF_TEST_P(Size_MatType_kSize, medianBlur,
  9. testing::Combine(
  10. testing::Values(szODD, szQVGA, szVGA, sz720p),
  11. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  12. testing::Values(3, 5)
  13. )
  14. )
  15. {
  16. Size size = get<0>(GetParam());
  17. int type = get<1>(GetParam());
  18. int ksize = get<2>(GetParam());
  19. Mat src(size, type);
  20. Mat dst(size, type);
  21. declare.in(src, WARMUP_RNG).out(dst);
  22. if (CV_MAT_DEPTH(type) > CV_16S || CV_MAT_CN(type) > 1)
  23. declare.time(15);
  24. TEST_CYCLE() medianBlur(src, dst, ksize);
  25. SANITY_CHECK(dst);
  26. }
  27. CV_ENUM(BorderType3x3, BORDER_REPLICATE, BORDER_CONSTANT)
  28. CV_ENUM(BorderType, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_REFLECT101)
  29. typedef tuple<Size, MatType, BorderType3x3> Size_MatType_BorderType3x3_t;
  30. typedef perf::TestBaseWithParam<Size_MatType_BorderType3x3_t> Size_MatType_BorderType3x3;
  31. typedef tuple<Size, MatType, BorderType> Size_MatType_BorderType_t;
  32. typedef perf::TestBaseWithParam<Size_MatType_BorderType_t> Size_MatType_BorderType;
  33. typedef tuple<Size, int, BorderType3x3> Size_ksize_BorderType_t;
  34. typedef perf::TestBaseWithParam<Size_ksize_BorderType_t> Size_ksize_BorderType;
  35. PERF_TEST_P(Size_MatType_BorderType3x3, gaussianBlur3x3,
  36. testing::Combine(
  37. testing::Values(szODD, szQVGA, szVGA, sz720p),
  38. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  39. BorderType3x3::all()
  40. )
  41. )
  42. {
  43. Size size = get<0>(GetParam());
  44. int type = get<1>(GetParam());
  45. BorderType3x3 btype = get<2>(GetParam());
  46. Mat src(size, type);
  47. Mat dst(size, type);
  48. declare.in(src, WARMUP_RNG).out(dst);
  49. TEST_CYCLE() GaussianBlur(src, dst, Size(3,3), 0, 0, btype);
  50. SANITY_CHECK(dst, 1);
  51. }
  52. PERF_TEST_P(Size_MatType_BorderType3x3, blur3x3,
  53. testing::Combine(
  54. testing::Values(szODD, szQVGA, szVGA, sz720p),
  55. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  56. BorderType3x3::all()
  57. )
  58. )
  59. {
  60. Size size = get<0>(GetParam());
  61. int type = get<1>(GetParam());
  62. BorderType3x3 btype = get<2>(GetParam());
  63. Mat src(size, type);
  64. Mat dst(size, type);
  65. declare.in(src, WARMUP_RNG).out(dst);
  66. TEST_CYCLE() blur(src, dst, Size(3,3), Point(-1,-1), btype);
  67. SANITY_CHECK(dst, 1);
  68. }
  69. PERF_TEST_P(Size_MatType_BorderType, blur16x16,
  70. testing::Combine(
  71. testing::Values(szVGA, sz720p),
  72. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  73. BorderType::all()
  74. )
  75. )
  76. {
  77. Size size = get<0>(GetParam());
  78. int type = get<1>(GetParam());
  79. BorderType btype = get<2>(GetParam());
  80. double eps = 1e-3;
  81. eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;
  82. Mat src(size, type);
  83. Mat dst(size, type);
  84. declare.in(src, WARMUP_RNG).out(dst);
  85. TEST_CYCLE() blur(src, dst, Size(16,16), Point(-1,-1), btype);
  86. SANITY_CHECK(dst, eps);
  87. }
  88. PERF_TEST_P(Size_MatType_BorderType3x3, box3x3,
  89. testing::Combine(
  90. testing::Values(szODD, szQVGA, szVGA, sz720p),
  91. testing::Values(CV_8UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_32FC3),
  92. BorderType3x3::all()
  93. )
  94. )
  95. {
  96. Size size = get<0>(GetParam());
  97. int type = get<1>(GetParam());
  98. BorderType3x3 btype = get<2>(GetParam());
  99. Mat src(size, type);
  100. Mat dst(size, type);
  101. declare.in(src, WARMUP_RNG).out(dst);
  102. TEST_CYCLE() boxFilter(src, dst, -1, Size(3,3), Point(-1,-1), false, btype);
  103. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  104. }
  105. PERF_TEST_P(Size_ksize_BorderType, box_CV8U_CV16U,
  106. testing::Combine(
  107. testing::Values(szODD, szQVGA, szVGA, sz720p),
  108. testing::Values(3, 5, 15),
  109. BorderType3x3::all()
  110. )
  111. )
  112. {
  113. Size size = get<0>(GetParam());
  114. int ksize = get<1>(GetParam());
  115. BorderType3x3 btype = get<2>(GetParam());
  116. Mat src(size, CV_8UC1);
  117. Mat dst(size, CV_16UC1);
  118. declare.in(src, WARMUP_RNG).out(dst);
  119. TEST_CYCLE() boxFilter(src, dst, CV_16UC1, Size(ksize, ksize), Point(-1,-1), false, btype);
  120. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  121. }
  122. PERF_TEST_P(Size_MatType_BorderType3x3, box3x3_inplace,
  123. testing::Combine(
  124. testing::Values(szODD, szQVGA, szVGA, sz720p),
  125. testing::Values(CV_8UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_32FC3),
  126. BorderType3x3::all()
  127. )
  128. )
  129. {
  130. Size size = get<0>(GetParam());
  131. int type = get<1>(GetParam());
  132. BorderType3x3 btype = get<2>(GetParam());
  133. Mat src(size, type);
  134. Mat dst(size, type);
  135. declare.in(src, WARMUP_RNG).out(dst);
  136. while(next())
  137. {
  138. src.copyTo(dst);
  139. startTimer();
  140. boxFilter(dst, dst, -1, Size(3,3), Point(-1,-1), false, btype);
  141. stopTimer();
  142. }
  143. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  144. }
  145. PERF_TEST_P(Size_MatType_BorderType, gaussianBlur5x5,
  146. testing::Combine(
  147. testing::Values(szODD, szQVGA, szVGA, sz720p),
  148. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  149. BorderType::all()
  150. )
  151. )
  152. {
  153. Size size = get<0>(GetParam());
  154. int type = get<1>(GetParam());
  155. BorderType btype = get<2>(GetParam());
  156. Mat src(size, type);
  157. Mat dst(size, type);
  158. declare.in(src, WARMUP_RNG).out(dst);
  159. TEST_CYCLE() GaussianBlur(src, dst, Size(5,5), 0, 0, btype);
  160. SANITY_CHECK(dst, 1);
  161. }
  162. PERF_TEST_P(Size_MatType_BorderType, blur5x5,
  163. testing::Combine(
  164. testing::Values(szVGA, sz720p),
  165. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1, CV_32FC3),
  166. BorderType::all()
  167. )
  168. )
  169. {
  170. Size size = get<0>(GetParam());
  171. int type = get<1>(GetParam());
  172. BorderType btype = get<2>(GetParam());
  173. Mat src(size, type);
  174. Mat dst(size, type);
  175. declare.in(src, WARMUP_RNG).out(dst);
  176. TEST_CYCLE() blur(src, dst, Size(5,5), Point(-1,-1), btype);
  177. SANITY_CHECK(dst, 1);
  178. }
  179. ///////////// BlendLinear ////////////////////////
  180. PERF_TEST_P(Size_MatType, BlendLinear,
  181. testing::Combine(
  182. testing::Values(szVGA, sz720p, sz1080p, sz2160p),
  183. testing::Values(CV_8UC1, CV_32FC1, CV_8UC3, CV_32FC3, CV_8UC4, CV_32FC4)
  184. )
  185. )
  186. {
  187. const Size srcSize = get<0>(GetParam());
  188. const int srcType = get<1>(GetParam());
  189. Mat src1(srcSize, srcType), src2(srcSize, srcType), dst(srcSize, srcType);
  190. Mat weights1(srcSize, CV_32FC1), weights2(srcSize, CV_32FC1);
  191. declare.in(src1, src2, WARMUP_RNG).in(weights1, weights2, WARMUP_READ).out(dst);
  192. randu(weights1, 0, 1);
  193. randu(weights2, 0, 1);
  194. TEST_CYCLE() blendLinear(src1, src2, weights1, weights2, dst);
  195. SANITY_CHECK_NOTHING();
  196. }
  197. } // namespace