Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/perf/perf_warp.cpp
16339 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
enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH};
9
10
CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE)
11
CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
12
CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
13
14
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpAffine;
15
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpPerspective;
16
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;
17
typedef TestBaseWithParam< tuple<MatType, Size, InterType, BorderMode, RemapMode> > TestRemap;
18
19
void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode );
20
21
PERF_TEST_P( TestWarpAffine, WarpAffine,
22
Combine(
23
Values( szVGA, sz720p, sz1080p ),
24
InterType::all(),
25
BorderMode::all()
26
)
27
)
28
{
29
Size sz, szSrc(512, 512);
30
int borderMode, interType;
31
sz = get<0>(GetParam());
32
interType = get<1>(GetParam());
33
borderMode = get<2>(GetParam());
34
Scalar borderColor = Scalar::all(150);
35
36
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
37
cvtest::fillGradient(src);
38
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
39
Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
40
declare.in(src).out(dst);
41
42
TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, borderColor );
43
44
#ifdef __ANDROID__
45
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
46
#else
47
SANITY_CHECK(dst, 1);
48
#endif
49
}
50
51
PERF_TEST_P(TestWarpAffine, WarpAffine_ovx,
52
Combine(
53
Values(szVGA, sz720p, sz1080p),
54
InterType::all(),
55
BorderMode::all()
56
)
57
)
58
{
59
Size sz, szSrc(512, 512);
60
int borderMode, interType;
61
sz = get<0>(GetParam());
62
interType = get<1>(GetParam());
63
borderMode = get<2>(GetParam());
64
Scalar borderColor = Scalar::all(150);
65
66
Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);
67
cvtest::fillGradient(src);
68
if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
69
Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);
70
declare.in(src).out(dst);
71
72
TEST_CYCLE() warpAffine(src, dst, warpMat, sz, interType, borderMode, borderColor);
73
74
#ifdef __ANDROID__
75
SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10);
76
#else
77
SANITY_CHECK(dst, 1);
78
#endif
79
}
80
81
PERF_TEST_P( TestWarpPerspective, WarpPerspective,
82
Combine(
83
Values( szVGA, sz720p, sz1080p ),
84
InterType::all(),
85
BorderMode::all()
86
)
87
)
88
{
89
Size sz, szSrc(512, 512);
90
int borderMode, interType;
91
sz = get<0>(GetParam());
92
interType = get<1>(GetParam());
93
borderMode = get<2>(GetParam());
94
Scalar borderColor = Scalar::all(150);
95
96
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
97
cvtest::fillGradient(src);
98
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
99
Mat rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
100
Mat warpMat(3, 3, CV_64FC1);
101
for(int r=0; r<2; r++)
102
for(int c=0; c<3; c++)
103
warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
104
warpMat.at<double>(2, 0) = .3/sz.width;
105
warpMat.at<double>(2, 1) = .3/sz.height;
106
warpMat.at<double>(2, 2) = 1;
107
108
declare.in(src).out(dst);
109
110
TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, borderColor );
111
112
#ifdef __ANDROID__
113
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
114
#else
115
SANITY_CHECK(dst, 1);
116
#endif
117
}
118
119
PERF_TEST_P(TestWarpPerspective, WarpPerspective_ovx,
120
Combine(
121
Values(szVGA, sz720p, sz1080p),
122
InterType::all(),
123
BorderMode::all()
124
)
125
)
126
{
127
Size sz, szSrc(512, 512);
128
int borderMode, interType;
129
sz = get<0>(GetParam());
130
interType = get<1>(GetParam());
131
borderMode = get<2>(GetParam());
132
Scalar borderColor = Scalar::all(150);
133
134
Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);
135
cvtest::fillGradient(src);
136
if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
137
Mat rotMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);
138
Mat warpMat(3, 3, CV_64FC1);
139
for (int r = 0; r<2; r++)
140
for (int c = 0; c<3; c++)
141
warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
142
warpMat.at<double>(2, 0) = .3 / sz.width;
143
warpMat.at<double>(2, 1) = .3 / sz.height;
144
warpMat.at<double>(2, 2) = 1;
145
146
declare.in(src).out(dst);
147
148
TEST_CYCLE() warpPerspective(src, dst, warpMat, sz, interType, borderMode, borderColor);
149
150
#ifdef __ANDROID__
151
SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10);
152
#else
153
SANITY_CHECK(dst, 1);
154
#endif
155
}
156
157
PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
158
Combine(
159
Values( Size(640,480), Size(1920,1080), Size(2592,1944) ),
160
InterType::all(),
161
BorderMode::all(),
162
Values( CV_8UC1, CV_8UC4 )
163
)
164
)
165
{
166
Size size;
167
int borderMode, interType, type;
168
size = get<0>(GetParam());
169
interType = get<1>(GetParam());
170
borderMode = get<2>(GetParam());
171
type = get<3>(GetParam());
172
Scalar borderColor = Scalar::all(150);
173
174
Mat src(size, type), dst(size, type);
175
cvtest::fillGradient(src);
176
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
177
int shift = static_cast<int>(src.cols*0.04);
178
Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0),
179
Vec2f(static_cast<float>(size.width-1), 0),
180
Vec2f(static_cast<float>(size.width-1), static_cast<float>(size.height-1)),
181
Vec2f(0, static_cast<float>(size.height-1)));
182
Mat dstVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, static_cast<float>(shift)),
183
Vec2f(static_cast<float>(size.width-shift/2), 0),
184
Vec2f(static_cast<float>(size.width-shift), static_cast<float>(size.height-shift)),
185
Vec2f(static_cast<float>(shift/2), static_cast<float>(size.height-1)));
186
Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);
187
188
declare.in(src).out(dst);
189
declare.time(100);
190
191
TEST_CYCLE()
192
{
193
warpPerspective( src, dst, warpMat, size, interType, borderMode, borderColor );
194
}
195
196
#ifdef __ANDROID__
197
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
198
#else
199
SANITY_CHECK(dst, 1);
200
#endif
201
}
202
203
PERF_TEST_P( TestRemap, remap,
204
Combine(
205
Values( CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1 ),
206
Values( szVGA, sz1080p ),
207
InterType::all(),
208
BorderMode::all(),
209
RemapMode::all()
210
)
211
)
212
{
213
int type = get<0>(GetParam());
214
Size size = get<1>(GetParam());
215
int interpolationType = get<2>(GetParam());
216
int borderMode = get<3>(GetParam());
217
int remapMode = get<4>(GetParam());
218
unsigned int height = size.height;
219
unsigned int width = size.width;
220
Mat source(height, width, type);
221
Mat destination;
222
Mat map_x(height, width, CV_32F);
223
Mat map_y(height, width, CV_32F);
224
225
declare.in(source, WARMUP_RNG);
226
227
update_map(source, map_x, map_y, remapMode);
228
229
TEST_CYCLE()
230
{
231
remap(source, destination, map_x, map_y, interpolationType, borderMode);
232
}
233
234
SANITY_CHECK_NOTHING();
235
}
236
237
void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode )
238
{
239
for( int j = 0; j < src.rows; j++ )
240
{
241
for( int i = 0; i < src.cols; i++ )
242
{
243
switch( remapMode )
244
{
245
case HALF_SIZE:
246
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
247
{
248
map_x.at<float>(j,i) = 2*( i - src.cols*0.25f ) + 0.5f ;
249
map_y.at<float>(j,i) = 2*( j - src.rows*0.25f ) + 0.5f ;
250
}
251
else
252
{
253
map_x.at<float>(j,i) = 0 ;
254
map_y.at<float>(j,i) = 0 ;
255
}
256
break;
257
case UPSIDE_DOWN:
258
map_x.at<float>(j,i) = static_cast<float>(i) ;
259
map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;
260
break;
261
case REFLECTION_X:
262
map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;
263
map_y.at<float>(j,i) = static_cast<float>(j) ;
264
break;
265
case REFLECTION_BOTH:
266
map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;
267
map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;
268
break;
269
} // end of switch
270
}
271
}
272
}
273
274
PERF_TEST(Transform, getPerspectiveTransform_1000)
275
{
276
unsigned int size = 8;
277
Mat source(1, size/2, CV_32FC2);
278
Mat destination(1, size/2, CV_32FC2);
279
Mat transformCoefficient;
280
281
declare.in(source, destination, WARMUP_RNG);
282
283
PERF_SAMPLE_BEGIN()
284
for (int i = 0; i < 1000; i++)
285
{
286
transformCoefficient = getPerspectiveTransform(source, destination);
287
}
288
PERF_SAMPLE_END()
289
290
SANITY_CHECK_NOTHING();
291
}
292
293
PERF_TEST(Transform, getPerspectiveTransform_QR_1000)
294
{
295
unsigned int size = 8;
296
Mat source(1, size/2, CV_32FC2);
297
Mat destination(1, size/2, CV_32FC2);
298
Mat transformCoefficient;
299
300
declare.in(source, destination, WARMUP_RNG);
301
302
PERF_SAMPLE_BEGIN()
303
for (int i = 0; i < 1000; i++)
304
{
305
transformCoefficient = getPerspectiveTransform(source, destination, DECOMP_QR);
306
}
307
PERF_SAMPLE_END()
308
309
SANITY_CHECK_NOTHING();
310
}
311
312
} // namespace
313
314