perf_threshold.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
  7. typedef tuple<Size, MatType, ThreshType> Size_MatType_ThreshType_t;
  8. typedef perf::TestBaseWithParam<Size_MatType_ThreshType_t> Size_MatType_ThreshType;
  9. PERF_TEST_P(Size_MatType_ThreshType, threshold,
  10. testing::Combine(
  11. testing::Values(TYPICAL_MAT_SIZES),
  12. testing::Values(CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1),
  13. ThreshType::all()
  14. )
  15. )
  16. {
  17. Size sz = get<0>(GetParam());
  18. int type = get<1>(GetParam());
  19. ThreshType threshType = get<2>(GetParam());
  20. Mat src(sz, type);
  21. Mat dst(sz, type);
  22. double thresh = theRNG().uniform(1, 254);
  23. double maxval = theRNG().uniform(1, 254);
  24. declare.in(src, WARMUP_RNG).out(dst);
  25. int runs = (sz.width <= 640) ? 40 : 1;
  26. TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, thresh, maxval, threshType);
  27. SANITY_CHECK(dst);
  28. }
  29. typedef perf::TestBaseWithParam<Size> Size_Only;
  30. PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))
  31. {
  32. Size sz = GetParam();
  33. Mat src(sz, CV_8UC1);
  34. Mat dst(sz, CV_8UC1);
  35. double maxval = theRNG().uniform(1, 254);
  36. declare.in(src, WARMUP_RNG).out(dst);
  37. int runs = 15;
  38. TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, 0, maxval, THRESH_BINARY|THRESH_OTSU);
  39. SANITY_CHECK(dst);
  40. }
  41. CV_ENUM(AdaptThreshType, THRESH_BINARY, THRESH_BINARY_INV)
  42. CV_ENUM(AdaptThreshMethod, ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C)
  43. typedef tuple<Size, AdaptThreshType, AdaptThreshMethod, int, double> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t;
  44. typedef perf::TestBaseWithParam<Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta;
  45. PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta, adaptiveThreshold,
  46. testing::Combine(
  47. testing::Values(TYPICAL_MAT_SIZES),
  48. AdaptThreshType::all(),
  49. AdaptThreshMethod::all(),
  50. testing::Values(3, 5),
  51. testing::Values(0.0, 10.0)
  52. )
  53. )
  54. {
  55. Size sz = get<0>(GetParam());
  56. AdaptThreshType adaptThreshType = get<1>(GetParam());
  57. AdaptThreshMethod adaptThreshMethod = get<2>(GetParam());
  58. int blockSize = get<3>(GetParam());
  59. double C = get<4>(GetParam());
  60. double maxValue = theRNG().uniform(1, 254);
  61. int type = CV_8UC1;
  62. Mat src_full(cv::Size(sz.width + 2, sz.height + 2), type);
  63. Mat src = src_full(cv::Rect(1, 1, sz.width, sz.height));
  64. Mat dst(sz, type);
  65. declare.in(src, WARMUP_RNG).out(dst);
  66. TEST_CYCLE() cv::adaptiveThreshold(src, dst, maxValue, adaptThreshMethod, adaptThreshType, blockSize, C);
  67. SANITY_CHECK(dst);
  68. }
  69. } // namespace