Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/perf/perf_threshold.cpp
16354 views
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
6
namespace opencv_test {
7
8
CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
9
10
typedef tuple<Size, MatType, ThreshType> Size_MatType_ThreshType_t;
11
typedef perf::TestBaseWithParam<Size_MatType_ThreshType_t> Size_MatType_ThreshType;
12
13
PERF_TEST_P(Size_MatType_ThreshType, threshold,
14
testing::Combine(
15
testing::Values(TYPICAL_MAT_SIZES),
16
testing::Values(CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1),
17
ThreshType::all()
18
)
19
)
20
{
21
22
Size sz = get<0>(GetParam());
23
int type = get<1>(GetParam());
24
ThreshType threshType = get<2>(GetParam());
25
26
Mat src(sz, type);
27
Mat dst(sz, type);
28
29
double thresh = theRNG().uniform(1, 254);
30
double maxval = theRNG().uniform(1, 254);
31
32
declare.in(src, WARMUP_RNG).out(dst);
33
34
int runs = (sz.width <= 640) ? 40 : 1;
35
TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, thresh, maxval, threshType);
36
37
SANITY_CHECK(dst);
38
}
39
40
typedef perf::TestBaseWithParam<Size> Size_Only;
41
42
PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))
43
{
44
Size sz = GetParam();
45
46
Mat src(sz, CV_8UC1);
47
Mat dst(sz, CV_8UC1);
48
49
double maxval = theRNG().uniform(1, 254);
50
51
declare.in(src, WARMUP_RNG).out(dst);
52
53
int runs = 15;
54
TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, 0, maxval, THRESH_BINARY|THRESH_OTSU);
55
56
SANITY_CHECK(dst);
57
}
58
59
CV_ENUM(AdaptThreshType, THRESH_BINARY, THRESH_BINARY_INV)
60
CV_ENUM(AdaptThreshMethod, ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C)
61
62
typedef tuple<Size, AdaptThreshType, AdaptThreshMethod, int, double> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t;
63
typedef perf::TestBaseWithParam<Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta;
64
65
PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta, adaptiveThreshold,
66
testing::Combine(
67
testing::Values(TYPICAL_MAT_SIZES),
68
AdaptThreshType::all(),
69
AdaptThreshMethod::all(),
70
testing::Values(3, 5),
71
testing::Values(0.0, 10.0)
72
)
73
)
74
{
75
Size sz = get<0>(GetParam());
76
AdaptThreshType adaptThreshType = get<1>(GetParam());
77
AdaptThreshMethod adaptThreshMethod = get<2>(GetParam());
78
int blockSize = get<3>(GetParam());
79
double C = get<4>(GetParam());
80
81
double maxValue = theRNG().uniform(1, 254);
82
83
int type = CV_8UC1;
84
85
Mat src_full(cv::Size(sz.width + 2, sz.height + 2), type);
86
Mat src = src_full(cv::Rect(1, 1, sz.width, sz.height));
87
Mat dst(sz, type);
88
89
declare.in(src, WARMUP_RNG).out(dst);
90
91
TEST_CYCLE() cv::adaptiveThreshold(src, dst, maxValue, adaptThreshMethod, adaptThreshType, blockSize, C);
92
93
SANITY_CHECK(dst);
94
}
95
96
} // namespace
97
98