perf_integral.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. enum PerfSqMatDepth{
  7. DEPTH_32S_32S = 0,
  8. DEPTH_32S_32F,
  9. DEPTH_32S_64F,
  10. DEPTH_32F_32F,
  11. DEPTH_32F_64F,
  12. DEPTH_64F_64F};
  13. CV_ENUM(IntegralOutputDepths, DEPTH_32S_32S, DEPTH_32S_32F, DEPTH_32S_64F, DEPTH_32F_32F, DEPTH_32F_64F, DEPTH_64F_64F);
  14. static int extraOutputDepths[6][2] = {{CV_32S, CV_32S}, {CV_32S, CV_32F}, {CV_32S, CV_64F}, {CV_32F, CV_32F}, {CV_32F, CV_64F}, {CV_64F, CV_64F}};
  15. typedef tuple<Size, MatType, MatDepth> Size_MatType_OutMatDepth_t;
  16. typedef perf::TestBaseWithParam<Size_MatType_OutMatDepth_t> Size_MatType_OutMatDepth;
  17. typedef tuple<Size, MatType, IntegralOutputDepths> Size_MatType_OutMatDepthArray_t;
  18. typedef perf::TestBaseWithParam<Size_MatType_OutMatDepthArray_t> Size_MatType_OutMatDepthArray;
  19. PERF_TEST_P(Size_MatType_OutMatDepth, integral,
  20. testing::Combine(
  21. testing::Values(TYPICAL_MAT_SIZES),
  22. testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4),
  23. testing::Values(CV_32S, CV_32F, CV_64F)
  24. )
  25. )
  26. {
  27. Size sz = get<0>(GetParam());
  28. int matType = get<1>(GetParam());
  29. int sdepth = get<2>(GetParam());
  30. Mat src(sz, matType);
  31. Mat sum(sz, sdepth);
  32. declare.in(src, WARMUP_RNG).out(sum);
  33. if (sdepth == CV_32F)
  34. src *= (1 << 23) / (double)(sz.area() * 256); // FP32 calculations are not accurate (mantissa is 23-bit)
  35. TEST_CYCLE() integral(src, sum, sdepth);
  36. Mat src_roi; src(Rect(src.cols - 4, src.rows - 4, 4, 4)).convertTo(src_roi, sdepth);
  37. Mat restored_src_roi =
  38. sum(Rect(sum.cols - 4, sum.rows - 4, 4, 4)) + sum(Rect(sum.cols - 5, sum.rows - 5, 4, 4)) -
  39. sum(Rect(sum.cols - 4, sum.rows - 5, 4, 4)) - sum(Rect(sum.cols - 5, sum.rows - 4, 4, 4));
  40. EXPECT_EQ(0, cvtest::norm(restored_src_roi, src_roi, NORM_INF))
  41. << src_roi << endl << restored_src_roi << endl
  42. << sum(Rect(sum.cols - 4, sum.rows - 4, 4, 4));
  43. if (sdepth == CV_32F)
  44. SANITY_CHECK_NOTHING();
  45. else
  46. SANITY_CHECK(sum, 1e-6);
  47. }
  48. PERF_TEST_P(Size_MatType_OutMatDepth, integral_sqsum,
  49. testing::Combine(
  50. testing::Values(TYPICAL_MAT_SIZES),
  51. testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4),
  52. testing::Values(CV_32S, CV_32F, CV_64F)
  53. )
  54. )
  55. {
  56. Size sz = get<0>(GetParam());
  57. int matType = get<1>(GetParam());
  58. int sdepth = get<2>(GetParam());
  59. Mat src(sz, matType);
  60. Mat sum(sz, sdepth);
  61. Mat sqsum(sz, sdepth);
  62. declare.in(src, WARMUP_RNG).out(sum, sqsum);
  63. declare.time(100);
  64. TEST_CYCLE() integral(src, sum, sqsum, sdepth);
  65. SANITY_CHECK(sum, 1e-6);
  66. SANITY_CHECK(sqsum, 1e-6);
  67. }
  68. PERF_TEST_P(Size_MatType_OutMatDepthArray, DISABLED_integral_sqsum_full,
  69. testing::Combine(
  70. testing::Values(TYPICAL_MAT_SIZES),
  71. testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4),
  72. testing::Values(DEPTH_32S_32S, DEPTH_32S_32F, DEPTH_32S_64F, DEPTH_32F_32F, DEPTH_32F_64F, DEPTH_64F_64F)
  73. )
  74. )
  75. {
  76. Size sz = get<0>(GetParam());
  77. int matType = get<1>(GetParam());
  78. int *outputDepths = (int *)extraOutputDepths[get<2>(GetParam())];
  79. int sdepth = outputDepths[0];
  80. int sqdepth = outputDepths[1];
  81. Mat src(sz, matType);
  82. Mat sum(sz, sdepth);
  83. Mat sqsum(sz, sqdepth);
  84. declare.in(src, WARMUP_RNG).out(sum, sqsum);
  85. declare.time(100);
  86. TEST_CYCLE() integral(src, sum, sqsum, sdepth, sqdepth);
  87. SANITY_CHECK_NOTHING();
  88. }
  89. PERF_TEST_P( Size_MatType_OutMatDepth, integral_sqsum_tilted,
  90. testing::Combine(
  91. testing::Values(TYPICAL_MAT_SIZES),
  92. testing::Values( CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4 ),
  93. testing::Values( CV_32S, CV_32F, CV_64F )
  94. )
  95. )
  96. {
  97. Size sz = get<0>(GetParam());
  98. int matType = get<1>(GetParam());
  99. int sdepth = get<2>(GetParam());
  100. Mat src(sz, matType);
  101. Mat sum(sz, sdepth);
  102. Mat sqsum(sz, sdepth);
  103. Mat tilted(sz, sdepth);
  104. declare.in(src, WARMUP_RNG).out(sum, sqsum, tilted);
  105. declare.time(100);
  106. TEST_CYCLE() integral(src, sum, sqsum, tilted, sdepth);
  107. SANITY_CHECK(sum, 1e-6);
  108. SANITY_CHECK(sqsum, 1e-6);
  109. SANITY_CHECK(tilted, 1e-6, tilted.depth() > CV_32S ? ERROR_RELATIVE : ERROR_ABSOLUTE);
  110. }
  111. } // namespace