1#include "perf_precomp.hpp"
2
3using namespace std;
4using namespace cv;
5using namespace perf;
6using std::tr1::make_tuple;
7using std::tr1::get;
8
9typedef std::tr1::tuple<Size, MatType, int> Size_MatType_kSize_t;
10typedef perf::TestBaseWithParam<Size_MatType_kSize_t> Size_MatType_kSize;
11
12PERF_TEST_P(Size_MatType_kSize, medianBlur,
13            testing::Combine(
14                testing::Values(szODD, szQVGA, szVGA, sz720p),
15                testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
16                testing::Values(3, 5)
17                )
18            )
19{
20    Size size = get<0>(GetParam());
21    int type = get<1>(GetParam());
22    int ksize = get<2>(GetParam());
23
24    Mat src(size, type);
25    Mat dst(size, type);
26
27    declare.in(src, WARMUP_RNG).out(dst);
28
29    if (CV_MAT_DEPTH(type) > CV_16S || CV_MAT_CN(type) > 1)
30        declare.time(15);
31
32    TEST_CYCLE() medianBlur(src, dst, ksize);
33
34    SANITY_CHECK(dst);
35}
36
37CV_ENUM(BorderType3x3, BORDER_REPLICATE, BORDER_CONSTANT)
38CV_ENUM(BorderType, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_REFLECT101)
39
40typedef std::tr1::tuple<Size, MatType, BorderType3x3> Size_MatType_BorderType3x3_t;
41typedef perf::TestBaseWithParam<Size_MatType_BorderType3x3_t> Size_MatType_BorderType3x3;
42
43typedef std::tr1::tuple<Size, MatType, BorderType> Size_MatType_BorderType_t;
44typedef perf::TestBaseWithParam<Size_MatType_BorderType_t> Size_MatType_BorderType;
45
46PERF_TEST_P(Size_MatType_BorderType3x3, gaussianBlur3x3,
47            testing::Combine(
48                testing::Values(szODD, szQVGA, szVGA, sz720p),
49                testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
50                BorderType3x3::all()
51                )
52            )
53{
54    Size size = get<0>(GetParam());
55    int type = get<1>(GetParam());
56    BorderType3x3 btype = get<2>(GetParam());
57
58    Mat src(size, type);
59    Mat dst(size, type);
60
61    declare.in(src, WARMUP_RNG).out(dst);
62
63    TEST_CYCLE() GaussianBlur(src, dst, Size(3,3), 0, 0, btype);
64
65    SANITY_CHECK(dst, 1);
66}
67
68PERF_TEST_P(Size_MatType_BorderType3x3, blur3x3,
69            testing::Combine(
70                testing::Values(szODD, szQVGA, szVGA, sz720p),
71                testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
72                BorderType3x3::all()
73                )
74            )
75{
76    Size size = get<0>(GetParam());
77    int type = get<1>(GetParam());
78    BorderType3x3 btype = get<2>(GetParam());
79
80    Mat src(size, type);
81    Mat dst(size, type);
82
83    declare.in(src, WARMUP_RNG).out(dst);
84
85    TEST_CYCLE() blur(src, dst, Size(3,3), Point(-1,-1), btype);
86
87    SANITY_CHECK(dst, 1);
88}
89
90PERF_TEST_P(Size_MatType_BorderType, blur16x16,
91            testing::Combine(
92                testing::Values(szVGA, sz720p),
93                testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
94                BorderType::all()
95                )
96            )
97{
98    Size size = get<0>(GetParam());
99    int type = get<1>(GetParam());
100    BorderType btype = get<2>(GetParam());
101    double eps = 1e-3;
102
103#if CV_NEON
104    eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;
105#endif
106
107    Mat src(size, type);
108    Mat dst(size, type);
109
110    declare.in(src, WARMUP_RNG).out(dst);
111
112    TEST_CYCLE() blur(src, dst, Size(16,16), Point(-1,-1), btype);
113
114    SANITY_CHECK(dst, eps);
115}
116
117PERF_TEST_P(Size_MatType_BorderType3x3, box3x3,
118            testing::Combine(
119                testing::Values(szODD, szQVGA, szVGA, sz720p),
120                testing::Values(CV_8UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_32FC3),
121                BorderType3x3::all()
122                )
123            )
124{
125    Size size = get<0>(GetParam());
126    int type = get<1>(GetParam());
127    BorderType3x3 btype = get<2>(GetParam());
128
129    Mat src(size, type);
130    Mat dst(size, type);
131
132    declare.in(src, WARMUP_RNG).out(dst);
133
134    TEST_CYCLE() boxFilter(src, dst, -1, Size(3,3), Point(-1,-1), false, btype);
135
136    SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
137}
138
139PERF_TEST_P(Size_MatType_BorderType3x3, box3x3_inplace,
140            testing::Combine(
141                testing::Values(szODD, szQVGA, szVGA, sz720p),
142                testing::Values(CV_8UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_32FC3),
143                BorderType3x3::all()
144                )
145            )
146{
147    Size size = get<0>(GetParam());
148    int type = get<1>(GetParam());
149    BorderType3x3 btype = get<2>(GetParam());
150
151    Mat src(size, type);
152    Mat dst(size, type);
153
154    declare.in(src, WARMUP_RNG).out(dst);
155
156    while(next())
157    {
158        src.copyTo(dst);
159        startTimer();
160        boxFilter(dst, dst, -1, Size(3,3), Point(-1,-1), false, btype);
161        stopTimer();
162    }
163
164    SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
165}
166
167PERF_TEST_P(Size_MatType_BorderType, gaussianBlur5x5,
168            testing::Combine(
169                testing::Values(szODD, szQVGA, szVGA, sz720p),
170                testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1),
171                BorderType::all()
172                )
173            )
174{
175    Size size = get<0>(GetParam());
176    int type = get<1>(GetParam());
177    BorderType btype = get<2>(GetParam());
178
179    Mat src(size, type);
180    Mat dst(size, type);
181
182    declare.in(src, WARMUP_RNG).out(dst);
183
184    TEST_CYCLE() GaussianBlur(src, dst, Size(5,5), 0, 0, btype);
185
186    SANITY_CHECK(dst, 1);
187}
188
189PERF_TEST_P(Size_MatType_BorderType, blur5x5,
190            testing::Combine(
191                testing::Values(szVGA, sz720p),
192                testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1, CV_32FC3),
193                BorderType::all()
194                )
195            )
196{
197    Size size = get<0>(GetParam());
198    int type = get<1>(GetParam());
199    BorderType btype = get<2>(GetParam());
200
201    Mat src(size, type);
202    Mat dst(size, type);
203
204    declare.in(src, WARMUP_RNG).out(dst);
205
206    TEST_CYCLE() blur(src, dst, Size(5,5), Point(-1,-1), btype);
207
208    SANITY_CHECK(dst, 1);
209}
210