1 #include "perf_precomp.hpp"
2
3 namespace opencv_test
4 {
5 using namespace perf;
6
7 #define HAMMING_NORM_SIZES cv::Size(640, 480), cv::Size(1920, 1080)
8 #define HAMMING_NORM_TYPES CV_8UC1
9
10 CV_FLAGS(NormType, NORM_HAMMING2, NORM_HAMMING, NORM_INF, NORM_L1, NORM_L2, NORM_TYPE_MASK, NORM_RELATIVE, NORM_MINMAX)
11 typedef tuple<Size, MatType, NormType> Size_MatType_NormType_t;
12 typedef perf::TestBaseWithParam<Size_MatType_NormType_t> Size_MatType_NormType;
13
14 PERF_TEST_P(Size_MatType_NormType, norm,
15 testing::Combine(
16 testing::Values(TYPICAL_MAT_SIZES),
17 testing::Values(TYPICAL_MAT_TYPES),
18 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
19 )
20 )
21 {
22 Size sz = get<0>(GetParam());
23 int matType = get<1>(GetParam());
24 int normType = get<2>(GetParam());
25
26 Mat src(sz, matType);
27 double n;
28
29 declare.in(src, WARMUP_RNG);
30
31 TEST_CYCLE() n = cv::norm(src, normType);
32
33 SANITY_CHECK(n, 1e-6, ERROR_RELATIVE);
34 }
35
36 PERF_TEST_P(Size_MatType_NormType, norm_mask,
37 testing::Combine(
38 testing::Values(TYPICAL_MAT_SIZES),
39 testing::Values(TYPICAL_MAT_TYPES),
40 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
41 )
42 )
43 {
44 Size sz = get<0>(GetParam());
45 int matType = get<1>(GetParam());
46 int normType = get<2>(GetParam());
47
48 Mat src(sz, matType);
49 Mat mask = Mat::ones(sz, CV_8U);
50 double n;
51
52 declare.in(src, WARMUP_RNG).in(mask);
53
54 TEST_CYCLE() n = cv::norm(src, normType, mask);
55
56 SANITY_CHECK(n, 1e-6, ERROR_RELATIVE);
57 }
58
59 PERF_TEST_P(Size_MatType_NormType, norm2,
60 testing::Combine(
61 testing::Values(TYPICAL_MAT_SIZES),
62 testing::Values(TYPICAL_MAT_TYPES),
63 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2, (int)(NORM_RELATIVE+NORM_INF), (int)(NORM_RELATIVE+NORM_L1), (int)(NORM_RELATIVE+NORM_L2))
64 )
65 )
66 {
67 Size sz = get<0>(GetParam());
68 int matType = get<1>(GetParam());
69 int normType = get<2>(GetParam());
70
71 Mat src1(sz, matType);
72 Mat src2(sz, matType);
73 double n;
74
75 declare.in(src1, src2, WARMUP_RNG);
76
77 TEST_CYCLE() n = cv::norm(src1, src2, normType);
78
79 SANITY_CHECK(n, 1e-5, ERROR_RELATIVE);
80 }
81
82 PERF_TEST_P(Size_MatType_NormType, norm2_mask,
83 testing::Combine(
84 testing::Values(TYPICAL_MAT_SIZES),
85 testing::Values(TYPICAL_MAT_TYPES),
86 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2, (int)(NORM_RELATIVE|NORM_INF), (int)(NORM_RELATIVE|NORM_L1), (int)(NORM_RELATIVE|NORM_L2))
87 )
88 )
89 {
90 Size sz = get<0>(GetParam());
91 int matType = get<1>(GetParam());
92 int normType = get<2>(GetParam());
93
94 Mat src1(sz, matType);
95 Mat src2(sz, matType);
96 Mat mask = Mat::ones(sz, CV_8U);
97 double n;
98
99 declare.in(src1, src2, WARMUP_RNG).in(mask);
100
101 TEST_CYCLE() n = cv::norm(src1, src2, normType, mask);
102
103 SANITY_CHECK(n, 1e-5, ERROR_RELATIVE);
104 }
105
106 namespace {
107 typedef tuple<NormType, MatType, Size> PerfHamming_t;
108 typedef perf::TestBaseWithParam<PerfHamming_t> PerfHamming;
109
PERF_TEST_P(PerfHamming,norm,testing::Combine (testing::Values (NORM_HAMMING,NORM_HAMMING2),testing::Values (HAMMING_NORM_TYPES),testing::Values (HAMMING_NORM_SIZES)))110 PERF_TEST_P(PerfHamming, norm,
111 testing::Combine(
112 testing::Values(NORM_HAMMING, NORM_HAMMING2),
113 testing::Values(HAMMING_NORM_TYPES),
114 testing::Values(HAMMING_NORM_SIZES)
115 )
116 )
117 {
118 Size sz = get<2>(GetParam());
119 int matType = get<1>(GetParam());
120 int normType = get<0>(GetParam());
121
122 Mat src(sz, matType);
123 double n;
124
125 declare.in(src, WARMUP_RNG);
126
127 TEST_CYCLE() n = cv::norm(src, normType);
128
129 CV_UNUSED(n);
130 SANITY_CHECK_NOTHING();
131 }
132
PERF_TEST_P(PerfHamming,norm2,testing::Combine (testing::Values (NORM_HAMMING,NORM_HAMMING2),testing::Values (HAMMING_NORM_TYPES),testing::Values (HAMMING_NORM_SIZES)))133 PERF_TEST_P(PerfHamming, norm2,
134 testing::Combine(
135 testing::Values(NORM_HAMMING, NORM_HAMMING2),
136 testing::Values(HAMMING_NORM_TYPES),
137 testing::Values(HAMMING_NORM_SIZES)
138 )
139 )
140 {
141 Size sz = get<2>(GetParam());
142 int matType = get<1>(GetParam());
143 int normType = get<0>(GetParam());
144
145 Mat src1(sz, matType);
146 Mat src2(sz, matType);
147 double n;
148
149 declare.in(src1, src2, WARMUP_RNG);
150
151 TEST_CYCLE() n = cv::norm(src1, src2, normType);
152
153 CV_UNUSED(n);
154 SANITY_CHECK_NOTHING();
155 }
156
157 }
158
159
160 PERF_TEST_P(Size_MatType_NormType, normalize,
161 testing::Combine(
162 testing::Values(TYPICAL_MAT_SIZES),
163 testing::Values(TYPICAL_MAT_TYPES),
164 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
165 )
166 )
167 {
168 Size sz = get<0>(GetParam());
169 int matType = get<1>(GetParam());
170 int normType = get<2>(GetParam());
171
172 Mat src(sz, matType);
173 Mat dst(sz, matType);
174
175 double alpha = 100.;
176 if(normType==NORM_L1) alpha = (double)src.total() * src.channels();
177 if(normType==NORM_L2) alpha = (double)src.total()/10;
178
179 declare.in(src, WARMUP_RNG).out(dst);
180
181 TEST_CYCLE() cv::normalize(src, dst, alpha, 0., normType);
182
183 SANITY_CHECK(dst, 1e-6);
184 }
185
186 PERF_TEST_P(Size_MatType_NormType, normalize_mask,
187 testing::Combine(
188 testing::Values(::perf::szVGA, ::perf::sz1080p),
189 testing::Values(TYPICAL_MAT_TYPES),
190 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
191 )
192 )
193 {
194 Size sz = get<0>(GetParam());
195 int matType = get<1>(GetParam());
196 int normType = get<2>(GetParam());
197
198 Mat src(sz, matType);
199 Mat dst(sz, matType);
200 Mat mask = Mat::ones(sz, CV_8U);
201
202 double alpha = 100.;
203 if(normType==NORM_L1) alpha = (double)src.total() * src.channels();
204 if(normType==NORM_L2) alpha = (double)src.total()/10;
205
206 declare.in(src, WARMUP_RNG).in(mask).out(dst);
207 declare.time(100);
208
209 TEST_CYCLE() cv::normalize(src, dst, alpha, 0., normType, -1, mask);
210
211 SANITY_CHECK(dst, 1e-6);
212 }
213
214 PERF_TEST_P(Size_MatType_NormType, normalize_32f,
215 testing::Combine(
216 testing::Values(TYPICAL_MAT_SIZES),
217 testing::Values(TYPICAL_MAT_TYPES),
218 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
219 )
220 )
221 {
222 Size sz = get<0>(GetParam());
223 int matType = get<1>(GetParam());
224 int normType = get<2>(GetParam());
225
226 Mat src(sz, matType);
227 Mat dst(sz, CV_32F);
228
229 double alpha = 100.;
230 if(normType==NORM_L1) alpha = (double)src.total() * src.channels();
231 if(normType==NORM_L2) alpha = (double)src.total()/10;
232
233 declare.in(src, WARMUP_RNG).out(dst);
234
235 TEST_CYCLE() cv::normalize(src, dst, alpha, 0., normType, CV_32F);
236
237 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
238 }
239
PERF_TEST_P(Size_MatType,normalize_minmax,TYPICAL_MATS)240 PERF_TEST_P( Size_MatType, normalize_minmax, TYPICAL_MATS )
241 {
242 Size sz = get<0>(GetParam());
243 int matType = get<1>(GetParam());
244
245 Mat src(sz, matType);
246 Mat dst(sz, matType);
247
248 declare.in(src, WARMUP_RNG).out(dst);
249 declare.time(30);
250
251 TEST_CYCLE() cv::normalize(src, dst, 20., 100., NORM_MINMAX);
252
253 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
254 }
255
256 typedef TestBaseWithParam< int > test_len;
257 PERF_TEST_P(test_len, hal_normL1_u8,
258 testing::Values(300000, 2000000)
259 )
260 {
261 int len = GetParam();
262
263 Mat src1(1, len, CV_8UC1);
264 Mat src2(1, len, CV_8UC1);
265
266 declare.in(src1, src2, WARMUP_RNG);
267 double n;
268 TEST_CYCLE() n = hal::normL1_(src1.ptr<uchar>(0), src2.ptr<uchar>(0), len);
269 CV_UNUSED(n);
270 SANITY_CHECK_NOTHING();
271 }
272
273 PERF_TEST_P(test_len, hal_normL1_f32,
274 testing::Values(300000, 2000000)
275 )
276 {
277 int len = GetParam();
278
279 Mat src1(1, len, CV_32FC1);
280 Mat src2(1, len, CV_32FC1);
281
282 declare.in(src1, src2, WARMUP_RNG);
283 double n;
284 TEST_CYCLE() n = hal::normL1_(src1.ptr<float>(0), src2.ptr<float>(0), len);
285 CV_UNUSED(n);
286 SANITY_CHECK_NOTHING();
287 }
288
289 PERF_TEST_P(test_len, hal_normL2Sqr,
290 testing::Values(300000, 2000000)
291 )
292 {
293 int len = GetParam();
294
295 Mat src1(1, len, CV_32FC1);
296 Mat src2(1, len, CV_32FC1);
297
298 declare.in(src1, src2, WARMUP_RNG);
299 double n;
300 TEST_CYCLE() n = hal::normL2Sqr_(src1.ptr<float>(0), src2.ptr<float>(0), len);
301 CV_UNUSED(n);
302 SANITY_CHECK_NOTHING();
303 }
304
305 } // namespace
306