perf_blur.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. typedef tuple<Size, MatType, BorderType, int> Size_MatType_BorderType_ksize_t;
  36. typedef perf::TestBaseWithParam<Size_MatType_BorderType_ksize_t> Size_MatType_BorderType_ksize;
  37. PERF_TEST_P(Size_MatType_BorderType3x3, gaussianBlur3x3,
  38. testing::Combine(
  39. testing::Values(szODD, szQVGA, szVGA, sz720p),
  40. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  41. BorderType3x3::all()
  42. )
  43. )
  44. {
  45. Size size = get<0>(GetParam());
  46. int type = get<1>(GetParam());
  47. BorderType3x3 btype = get<2>(GetParam());
  48. Mat src(size, type);
  49. Mat dst(size, type);
  50. declare.in(src, WARMUP_RNG).out(dst);
  51. TEST_CYCLE() GaussianBlur(src, dst, Size(3,3), 0, 0, btype);
  52. SANITY_CHECK(dst, 1);
  53. }
  54. PERF_TEST_P(Size_MatType_BorderType3x3, blur3x3,
  55. testing::Combine(
  56. testing::Values(szODD, szQVGA, szVGA, sz720p),
  57. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  58. BorderType3x3::all()
  59. )
  60. )
  61. {
  62. Size size = get<0>(GetParam());
  63. int type = get<1>(GetParam());
  64. BorderType3x3 btype = get<2>(GetParam());
  65. Mat src(size, type);
  66. Mat dst(size, type);
  67. declare.in(src, WARMUP_RNG).out(dst);
  68. TEST_CYCLE() blur(src, dst, Size(3,3), Point(-1,-1), btype);
  69. SANITY_CHECK(dst, 1);
  70. }
  71. PERF_TEST_P(Size_MatType_BorderType, blur16x16,
  72. testing::Combine(
  73. testing::Values(szVGA, sz720p),
  74. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  75. BorderType::all()
  76. )
  77. )
  78. {
  79. Size size = get<0>(GetParam());
  80. int type = get<1>(GetParam());
  81. BorderType btype = get<2>(GetParam());
  82. double eps = 1.25e-3;
  83. eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;
  84. Mat src(size, type);
  85. Mat dst(size, type);
  86. declare.in(src, WARMUP_RNG).out(dst);
  87. TEST_CYCLE() blur(src, dst, Size(16,16), Point(-1,-1), btype);
  88. SANITY_CHECK(dst, eps);
  89. }
  90. PERF_TEST_P(Size_MatType_BorderType_ksize, box,
  91. testing::Combine(
  92. testing::Values(szODD, szQVGA, szVGA, sz720p),
  93. testing::Values(CV_8UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_32FC3),
  94. BorderType::all(),
  95. testing::Values(3, 5)
  96. )
  97. )
  98. {
  99. auto p = GetParam();
  100. Size size = get<0>(p);
  101. int type = get<1>(p);
  102. BorderType btype = get<2>(p);
  103. int ksize = get<3>(p);
  104. Mat src(size, type);
  105. Mat dst(size, type);
  106. declare.in(src, WARMUP_RNG).out(dst);
  107. TEST_CYCLE() boxFilter(src, dst, -1, Size(ksize, ksize), Point(-1,-1), false, btype);
  108. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  109. }
  110. PERF_TEST_P(Size_ksize_BorderType, box_CV8U_CV16U,
  111. testing::Combine(
  112. testing::Values(szODD, szQVGA, szVGA, sz720p),
  113. testing::Values(3, 5, 15),
  114. BorderType3x3::all()
  115. )
  116. )
  117. {
  118. Size size = get<0>(GetParam());
  119. int ksize = get<1>(GetParam());
  120. BorderType3x3 btype = get<2>(GetParam());
  121. Mat src(size, CV_8UC1);
  122. Mat dst(size, CV_16UC1);
  123. declare.in(src, WARMUP_RNG).out(dst);
  124. TEST_CYCLE() boxFilter(src, dst, CV_16UC1, Size(ksize, ksize), Point(-1,-1), false, btype);
  125. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  126. }
  127. PERF_TEST_P(Size_MatType_BorderType_ksize, box_inplace,
  128. testing::Combine(
  129. testing::Values(szODD, szQVGA, szVGA, sz720p),
  130. testing::Values(CV_8UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_32FC3),
  131. BorderType::all(),
  132. testing::Values(3, 5)
  133. )
  134. )
  135. {
  136. auto p = GetParam();
  137. Size size = get<0>(p);
  138. int type = get<1>(p);
  139. BorderType btype = get<2>(p);
  140. int ksize = get<3>(p);
  141. Mat src(size, type);
  142. Mat dst(size, type);
  143. declare.in(src, WARMUP_RNG).out(dst);
  144. while(next())
  145. {
  146. src.copyTo(dst);
  147. startTimer();
  148. boxFilter(dst, dst, -1, Size(ksize, ksize), Point(-1,-1), false, btype);
  149. stopTimer();
  150. }
  151. SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  152. }
  153. PERF_TEST_P(Size_MatType_BorderType, gaussianBlur5x5,
  154. testing::Combine(
  155. testing::Values(szODD, szQVGA, szVGA, sz720p),
  156. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
  157. BorderType::all()
  158. )
  159. )
  160. {
  161. Size size = get<0>(GetParam());
  162. int type = get<1>(GetParam());
  163. BorderType btype = get<2>(GetParam());
  164. Mat src(size, type);
  165. Mat dst(size, type);
  166. declare.in(src, WARMUP_RNG).out(dst);
  167. TEST_CYCLE() GaussianBlur(src, dst, Size(5,5), 0, 0, btype);
  168. SANITY_CHECK(dst, 1);
  169. }
  170. PERF_TEST_P(Size_MatType_BorderType, blur5x5,
  171. testing::Combine(
  172. testing::Values(szVGA, sz720p),
  173. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1, CV_32FC3),
  174. BorderType::all()
  175. )
  176. )
  177. {
  178. Size size = get<0>(GetParam());
  179. int type = get<1>(GetParam());
  180. BorderType btype = get<2>(GetParam());
  181. Mat src(size, type);
  182. Mat dst(size, type);
  183. declare.in(src, WARMUP_RNG).out(dst);
  184. TEST_CYCLE() blur(src, dst, Size(5,5), Point(-1,-1), btype);
  185. SANITY_CHECK(dst, 1);
  186. }
  187. ///////////// BlendLinear ////////////////////////
  188. PERF_TEST_P(Size_MatType, BlendLinear,
  189. testing::Combine(
  190. testing::Values(szVGA, sz720p, sz1080p, sz2160p),
  191. testing::Values(CV_8UC1, CV_32FC1, CV_8UC3, CV_32FC3, CV_8UC4, CV_32FC4)
  192. )
  193. )
  194. {
  195. const Size srcSize = get<0>(GetParam());
  196. const int srcType = get<1>(GetParam());
  197. Mat src1(srcSize, srcType), src2(srcSize, srcType), dst(srcSize, srcType);
  198. Mat weights1(srcSize, CV_32FC1), weights2(srcSize, CV_32FC1);
  199. declare.in(src1, src2, WARMUP_RNG).in(weights1, weights2, WARMUP_READ).out(dst);
  200. randu(weights1, 0, 1);
  201. randu(weights2, 0, 1);
  202. TEST_CYCLE() blendLinear(src1, src2, weights1, weights2, dst);
  203. SANITY_CHECK_NOTHING();
  204. }
  205. ///////////// Stackblur ////////////////////////
  206. PERF_TEST_P(Size_MatType, stackblur3x3,
  207. testing::Combine(
  208. testing::Values(sz720p, sz1080p, sz2160p),
  209. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1)
  210. )
  211. )
  212. {
  213. Size size = get<0>(GetParam());
  214. int type = get<1>(GetParam());
  215. double eps = 1e-3;
  216. eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;
  217. Mat src(size, type);
  218. Mat dst(size, type);
  219. declare.in(src, WARMUP_RNG).out(dst);
  220. TEST_CYCLE() stackBlur(src, dst, Size(3,3));
  221. SANITY_CHECK_NOTHING();
  222. }
  223. PERF_TEST_P(Size_MatType, stackblur101x101,
  224. testing::Combine(
  225. testing::Values(sz720p, sz1080p, sz2160p),
  226. testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1)
  227. )
  228. )
  229. {
  230. Size size = get<0>(GetParam());
  231. int type = get<1>(GetParam());
  232. double eps = 1e-3;
  233. eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;
  234. Mat src(size, type);
  235. Mat dst(size, type);
  236. declare.in(src, WARMUP_RNG).out(dst);
  237. TEST_CYCLE() stackBlur(src, dst, Size(101,101));
  238. SANITY_CHECK_NOTHING();
  239. }
  240. } // namespace