Blame view

3rdparty/opencv-4.5.4/modules/imgproc/perf/perf_threshold.cpp 3.02 KB
f4334277   Hu Chunming   提交3rdparty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  // This file is part of OpenCV project.
  // It is subject to the license terms in the LICENSE file found in the top-level directory
  // of this distribution and at http://opencv.org/license.html.
  #include "perf_precomp.hpp"
  
  namespace opencv_test {
  
  CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
  
  typedef tuple<Size, MatType, ThreshType> Size_MatType_ThreshType_t;
  typedef perf::TestBaseWithParam<Size_MatType_ThreshType_t> Size_MatType_ThreshType;
  
  PERF_TEST_P(Size_MatType_ThreshType, threshold,
              testing::Combine(
                  testing::Values(TYPICAL_MAT_SIZES),
                  testing::Values(CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1),
                  ThreshType::all()
                  )
              )
  {
  
      Size sz = get<0>(GetParam());
      int type = get<1>(GetParam());
      ThreshType threshType = get<2>(GetParam());
  
      Mat src(sz, type);
      Mat dst(sz, type);
  
      double thresh = theRNG().uniform(1, 254);
      double maxval = theRNG().uniform(1, 254);
  
      declare.in(src, WARMUP_RNG).out(dst);
  
      int runs = (sz.width <= 640) ? 40 : 1;
      TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, thresh, maxval, threshType);
  
      SANITY_CHECK(dst);
  }
  
  typedef perf::TestBaseWithParam<Size> Size_Only;
  
  PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))
  {
      Size sz = GetParam();
  
      Mat src(sz, CV_8UC1);
      Mat dst(sz, CV_8UC1);
  
      double maxval = theRNG().uniform(1, 254);
  
      declare.in(src, WARMUP_RNG).out(dst);
  
      int runs = 15;
      TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, 0, maxval, THRESH_BINARY|THRESH_OTSU);
  
      SANITY_CHECK(dst);
  }
  
  CV_ENUM(AdaptThreshType, THRESH_BINARY, THRESH_BINARY_INV)
  CV_ENUM(AdaptThreshMethod, ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C)
  
  typedef tuple<Size, AdaptThreshType, AdaptThreshMethod, int, double> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t;
  typedef perf::TestBaseWithParam<Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta;
  
  PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta, adaptiveThreshold,
              testing::Combine(
                  testing::Values(TYPICAL_MAT_SIZES),
                  AdaptThreshType::all(),
                  AdaptThreshMethod::all(),
                  testing::Values(3, 5),
                  testing::Values(0.0, 10.0)
                  )
              )
  {
      Size sz = get<0>(GetParam());
      AdaptThreshType adaptThreshType = get<1>(GetParam());
      AdaptThreshMethod adaptThreshMethod = get<2>(GetParam());
      int blockSize = get<3>(GetParam());
      double C = get<4>(GetParam());
  
      double maxValue = theRNG().uniform(1, 254);
  
      int type = CV_8UC1;
  
      Mat src_full(cv::Size(sz.width + 2, sz.height + 2), type);
      Mat src = src_full(cv::Rect(1, 1, sz.width, sz.height));
      Mat dst(sz, type);
  
      declare.in(src, WARMUP_RNG).out(dst);
  
      TEST_CYCLE() cv::adaptiveThreshold(src, dst, maxValue, adaptThreshMethod, adaptThreshType, blockSize, C);
  
      SANITY_CHECK(dst);
  }
  
  } // namespace