perf_histogram.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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> Size_Source_t;
  7. typedef TestBaseWithParam<Size_Source_t> Size_Source;
  8. typedef TestBaseWithParam<Size> TestMatSize;
  9. static const float rangeHight = 256.0f;
  10. static const float rangeLow = 0.0f;
  11. PERF_TEST_P(Size_Source, calcHist1d,
  12. testing::Combine(testing::Values(sz3MP, sz5MP),
  13. testing::Values(CV_8U, CV_16U, CV_32F) )
  14. )
  15. {
  16. Size size = get<0>(GetParam());
  17. MatType type = get<1>(GetParam());
  18. Mat source(size.height, size.width, type);
  19. Mat hist;
  20. int channels [] = {0};
  21. int histSize [] = {256};
  22. int dims = 1;
  23. int numberOfImages = 1;
  24. const float range[] = {rangeLow, rangeHight};
  25. const float* ranges[] = {range};
  26. randu(source, rangeLow, rangeHight);
  27. declare.in(source);
  28. TEST_CYCLE_MULTIRUN(3)
  29. {
  30. calcHist(&source, numberOfImages, channels, Mat(), hist, dims, histSize, ranges);
  31. }
  32. SANITY_CHECK(hist);
  33. }
  34. PERF_TEST_P(Size_Source, calcHist2d,
  35. testing::Combine(testing::Values(sz3MP, sz5MP),
  36. testing::Values(CV_8UC2, CV_16UC2, CV_32FC2) )
  37. )
  38. {
  39. Size size = get<0>(GetParam());
  40. MatType type = get<1>(GetParam());
  41. Mat source(size.height, size.width, type);
  42. Mat hist;
  43. int channels [] = {0, 1};
  44. int histSize [] = {256, 256};
  45. int dims = 2;
  46. int numberOfImages = 1;
  47. const float r[] = {rangeLow, rangeHight};
  48. const float* ranges[] = {r, r};
  49. randu(source, rangeLow, rangeHight);
  50. declare.in(source);
  51. TEST_CYCLE()
  52. {
  53. calcHist(&source, numberOfImages, channels, Mat(), hist, dims, histSize, ranges);
  54. }
  55. SANITY_CHECK(hist);
  56. }
  57. PERF_TEST_P(Size_Source, calcHist3d,
  58. testing::Combine(testing::Values(sz3MP, sz5MP),
  59. testing::Values(CV_8UC3, CV_16UC3, CV_32FC3) )
  60. )
  61. {
  62. Size size = get<0>(GetParam());
  63. MatType type = get<1>(GetParam());
  64. Mat hist;
  65. int channels [] = {0, 1, 2};
  66. int histSize [] = {32, 32, 32};
  67. int dims = 3;
  68. int numberOfImages = 1;
  69. Mat source(size.height, size.width, type);
  70. const float r[] = {rangeLow, rangeHight};
  71. const float* ranges[] = {r, r, r};
  72. randu(source, rangeLow, rangeHight);
  73. declare.in(source);
  74. TEST_CYCLE()
  75. {
  76. calcHist(&source, numberOfImages, channels, Mat(), hist, dims, histSize, ranges);
  77. }
  78. SANITY_CHECK(hist);
  79. }
  80. #define MatSize TestMatSize
  81. PERF_TEST_P(MatSize, equalizeHist,
  82. testing::Values(TYPICAL_MAT_SIZES)
  83. )
  84. {
  85. Size size = GetParam();
  86. Mat source(size.height, size.width, CV_8U);
  87. Mat destination;
  88. declare.in(source, WARMUP_RNG);
  89. TEST_CYCLE()
  90. {
  91. equalizeHist(source, destination);
  92. }
  93. SANITY_CHECK(destination);
  94. }
  95. #undef MatSize
  96. typedef TestBaseWithParam< tuple<int, int> > Dim_Cmpmethod;
  97. PERF_TEST_P(Dim_Cmpmethod, compareHist,
  98. testing::Combine(testing::Values(1, 3),
  99. testing::Values(HISTCMP_CORREL, HISTCMP_CHISQR, HISTCMP_INTERSECT, HISTCMP_BHATTACHARYYA, HISTCMP_CHISQR_ALT, HISTCMP_KL_DIV))
  100. )
  101. {
  102. int dims = get<0>(GetParam());
  103. int method = get<1>(GetParam());
  104. int histSize[] = { 2048, 128, 64 };
  105. Mat hist1(dims, histSize, CV_32FC1);
  106. Mat hist2(dims, histSize, CV_32FC1);
  107. randu(hist1, 0, 256);
  108. randu(hist2, 0, 256);
  109. declare.in(hist1.reshape(1, 256), hist2.reshape(1, 256));
  110. TEST_CYCLE()
  111. {
  112. compareHist(hist1, hist2, method);
  113. }
  114. SANITY_CHECK_NOTHING();
  115. }
  116. typedef tuple<Size, double, MatType> Sz_ClipLimit_t;
  117. typedef TestBaseWithParam<Sz_ClipLimit_t> Sz_ClipLimit;
  118. PERF_TEST_P(Sz_ClipLimit, CLAHE,
  119. testing::Combine(testing::Values(::perf::szVGA, ::perf::sz720p, ::perf::sz1080p),
  120. testing::Values(0.0, 40.0),
  121. testing::Values(MatType(CV_8UC1), MatType(CV_16UC1)))
  122. )
  123. {
  124. const Size size = get<0>(GetParam());
  125. const double clipLimit = get<1>(GetParam());
  126. const int type = get<2>(GetParam());
  127. Mat src(size, type);
  128. declare.in(src, WARMUP_RNG);
  129. Ptr<CLAHE> clahe = createCLAHE(clipLimit);
  130. Mat dst;
  131. TEST_CYCLE() clahe->apply(src, dst);
  132. SANITY_CHECK(dst);
  133. }
  134. } // namespace