1 #include "perf_precomp.hpp"
2
3 using namespace std;
4 using namespace cv;
5 using namespace perf;
6 using std::tr1::make_tuple;
7 using std::tr1::get;
8
9
10 CV_FLAGS(NormType, NORM_INF, NORM_L1, NORM_L2, NORM_TYPE_MASK, NORM_RELATIVE, NORM_MINMAX)
11 typedef std::tr1::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 = 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 = 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 = 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 = norm(src1, src2, normType, mask);
102
103 SANITY_CHECK(n, 1e-5, ERROR_RELATIVE);
104 }
105
106 PERF_TEST_P(Size_MatType_NormType, normalize,
107 testing::Combine(
108 testing::Values(TYPICAL_MAT_SIZES),
109 testing::Values(TYPICAL_MAT_TYPES),
110 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
111 )
112 )
113 {
114 Size sz = get<0>(GetParam());
115 int matType = get<1>(GetParam());
116 int normType = get<2>(GetParam());
117
118 Mat src(sz, matType);
119 Mat dst(sz, matType);
120
121 double alpha = 100.;
122 if(normType==NORM_L1) alpha = (double)src.total() * src.channels();
123 if(normType==NORM_L2) alpha = (double)src.total()/10;
124
125 declare.in(src, WARMUP_RNG).out(dst);
126
127 TEST_CYCLE() normalize(src, dst, alpha, 0., normType);
128
129 SANITY_CHECK(dst, 1e-6);
130 }
131
132 PERF_TEST_P(Size_MatType_NormType, normalize_mask,
133 testing::Combine(
134 testing::Values(::perf::szVGA, ::perf::sz1080p),
135 testing::Values(TYPICAL_MAT_TYPES),
136 testing::Values((int)NORM_INF, (int)NORM_L1, (int)NORM_L2)
137 )
138 )
139 {
140 Size sz = get<0>(GetParam());
141 int matType = get<1>(GetParam());
142 int normType = get<2>(GetParam());
143
144 Mat src(sz, matType);
145 Mat dst(sz, matType);
146 Mat mask = Mat::ones(sz, CV_8U);
147
148 double alpha = 100.;
149 if(normType==NORM_L1) alpha = (double)src.total() * src.channels();
150 if(normType==NORM_L2) alpha = (double)src.total()/10;
151
152 declare.in(src, WARMUP_RNG).in(mask).out(dst);
153 declare.time(100);
154
155 TEST_CYCLE() normalize(src, dst, alpha, 0., normType, -1, mask);
156
157 SANITY_CHECK(dst, 1e-6);
158 }
159
160 PERF_TEST_P(Size_MatType_NormType, normalize_32f,
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, CV_32F);
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() normalize(src, dst, alpha, 0., normType, CV_32F);
182
183 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
184 }
185
PERF_TEST_P(Size_MatType,normalize_minmax,TYPICAL_MATS)186 PERF_TEST_P( Size_MatType, normalize_minmax, TYPICAL_MATS )
187 {
188 Size sz = get<0>(GetParam());
189 int matType = get<1>(GetParam());
190
191 Mat src(sz, matType);
192 Mat dst(sz, matType);
193
194 declare.in(src, WARMUP_RNG).out(dst);
195 declare.time(30);
196
197 TEST_CYCLE() normalize(src, dst, 20., 100., NORM_MINMAX);
198
199 SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
200 }
201