Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/perf/opencl/perf_imgwarp.cpp
16350 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// @Authors
18
// Fangfang Bai, [email protected]
19
// Jin Ma, [email protected]
20
//
21
// Redistribution and use in source and binary forms, with or without modification,
22
// are permitted provided that the following conditions are met:
23
//
24
// * Redistribution's of source code must retain the above copyright notice,
25
// this list of conditions and the following disclaimer.
26
//
27
// * Redistribution's in binary form must reproduce the above copyright notice,
28
// this list of conditions and the following disclaimer in the documentation
29
// and/or other materials provided with the distribution.
30
//
31
// * The name of the copyright holders may not be used to endorse or promote products
32
// derived from this software without specific prior written permission.
33
//
34
// This software is provided by the copyright holders and contributors as is and
35
// any express or implied warranties, including, but not limited to, the implied
36
// warranties of merchantability and fitness for a particular purpose are disclaimed.
37
// In no event shall the Intel Corporation or contributors be liable for any direct,
38
// indirect, incidental, special, exemplary, or consequential damages
39
// (including, but not limited to, procurement of substitute goods or services;
40
// loss of use, data, or profits; or business interruption) however caused
41
// and on any theory of liability, whether in contract, strict liability,
42
// or tort (including negligence or otherwise) arising in any way out of
43
// the use of this software, even if advised of the possibility of such damage.
44
//
45
//M*/
46
47
#include "../perf_precomp.hpp"
48
#include "opencv2/ts/ocl_perf.hpp"
49
50
#ifdef HAVE_OPENCL
51
52
namespace opencv_test {
53
namespace ocl {
54
55
///////////// WarpAffine ////////////////////////
56
57
CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
58
59
typedef tuple<Size, MatType, InterType> WarpAffineParams;
60
typedef TestBaseWithParam<WarpAffineParams> WarpAffineFixture;
61
62
OCL_PERF_TEST_P(WarpAffineFixture, WarpAffine,
63
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, InterType::all()))
64
{
65
static const double coeffs[2][3] =
66
{
67
{ cos(CV_PI / 6), -sin(CV_PI / 6), 100.0 },
68
{ sin(CV_PI / 6), cos(CV_PI / 6) , -100.0 }
69
};
70
Mat M(2, 3, CV_64F, (void *)coeffs);
71
72
const WarpAffineParams params = GetParam();
73
const Size srcSize = get<0>(params);
74
const int type = get<1>(params), interpolation = get<2>(params);
75
const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : interpolation == INTER_CUBIC ? 2e-3 : 1e-4;
76
77
checkDeviceMaxMemoryAllocSize(srcSize, type);
78
79
UMat src(srcSize, type), dst(srcSize, type);
80
declare.in(src, WARMUP_RNG).out(dst);
81
82
OCL_TEST_CYCLE() cv::warpAffine(src, dst, M, srcSize, interpolation);
83
84
SANITY_CHECK(dst, eps);
85
}
86
87
///////////// WarpPerspective ////////////////////////
88
89
typedef WarpAffineParams WarpPerspectiveParams;
90
typedef TestBaseWithParam<WarpPerspectiveParams> WarpPerspectiveFixture;
91
92
OCL_PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective,
93
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
94
OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))
95
{
96
static const double coeffs[3][3] =
97
{
98
{cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},
99
{sin(CV_PI / 6), cos(CV_PI / 6), -100.0},
100
{0.0, 0.0, 1.0}
101
};
102
Mat M(3, 3, CV_64F, (void *)coeffs);
103
104
const WarpPerspectiveParams params = GetParam();
105
const Size srcSize = get<0>(params);
106
const int type = get<1>(params), interpolation = get<2>(params);
107
const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
108
109
checkDeviceMaxMemoryAllocSize(srcSize, type);
110
111
UMat src(srcSize, type), dst(srcSize, type);
112
declare.in(src, WARMUP_RNG).out(dst);
113
114
OCL_TEST_CYCLE() cv::warpPerspective(src, dst, M, srcSize, interpolation);
115
116
SANITY_CHECK(dst, eps);
117
}
118
119
///////////// Resize ////////////////////////
120
121
typedef tuple<Size, MatType, InterType, double> ResizeParams;
122
typedef TestBaseWithParam<ResizeParams> ResizeFixture;
123
124
OCL_PERF_TEST_P(ResizeFixture, Resize,
125
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
126
OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR)),
127
::testing::Values(0.5, 2.0)))
128
{
129
const ResizeParams params = GetParam();
130
const Size srcSize = get<0>(params);
131
const int type = get<1>(params), interType = get<2>(params);
132
double scale = get<3>(params);
133
const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
134
const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
135
136
checkDeviceMaxMemoryAllocSize(srcSize, type);
137
checkDeviceMaxMemoryAllocSize(dstSize, type);
138
139
UMat src(srcSize, type), dst(dstSize, type);
140
declare.in(src, WARMUP_RNG).out(dst);
141
142
OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, interType);
143
144
SANITY_CHECK(dst, eps);
145
}
146
147
typedef tuple<Size, MatType, double> ResizeAreaParams;
148
typedef TestBaseWithParam<ResizeAreaParams> ResizeAreaFixture;
149
150
OCL_PERF_TEST_P(ResizeAreaFixture, Resize,
151
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, ::testing::Values(0.3, 0.5, 0.6)))
152
{
153
const ResizeAreaParams params = GetParam();
154
const Size srcSize = get<0>(params);
155
const int type = get<1>(params);
156
double scale = get<2>(params);
157
const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
158
const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
159
160
checkDeviceMaxMemoryAllocSize(srcSize, type);
161
checkDeviceMaxMemoryAllocSize(dstSize, type);
162
163
UMat src(srcSize, type), dst(dstSize, type);
164
declare.in(src, WARMUP_RNG).out(dst);
165
166
OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_AREA);
167
168
SANITY_CHECK(dst, eps);
169
}
170
171
typedef ResizeAreaParams ResizeLinearExactParams;
172
typedef TestBaseWithParam<ResizeLinearExactParams> ResizeLinearExactFixture;
173
174
OCL_PERF_TEST_P(ResizeLinearExactFixture, Resize,
175
::testing::Combine(OCL_TEST_SIZES, ::testing::Values(CV_8UC1, CV_8UC3, CV_8UC4), ::testing::Values(0.5, 2.0)))
176
{
177
const ResizeAreaParams params = GetParam();
178
const Size srcSize = get<0>(params);
179
const int type = get<1>(params);
180
double scale = get<2>(params);
181
const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
182
const double eps = 1e-4;
183
184
checkDeviceMaxMemoryAllocSize(srcSize, type);
185
checkDeviceMaxMemoryAllocSize(dstSize, type);
186
187
UMat src(srcSize, type), dst(dstSize, type);
188
declare.in(src, WARMUP_RNG).out(dst);
189
190
OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_LINEAR_EXACT);
191
192
SANITY_CHECK(dst, eps);
193
}
194
195
///////////// Remap ////////////////////////
196
197
typedef tuple<Size, MatType, InterType> RemapParams;
198
typedef TestBaseWithParam<RemapParams> RemapFixture;
199
200
OCL_PERF_TEST_P(RemapFixture, Remap,
201
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
202
OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))
203
{
204
const RemapParams params = GetParam();
205
const Size srcSize = get<0>(params);
206
const int type = get<1>(params), interpolation = get<2>(params), borderMode = BORDER_CONSTANT;
207
//const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
208
209
checkDeviceMaxMemoryAllocSize(srcSize, type);
210
211
UMat src(srcSize, type), dst(srcSize, type);
212
UMat xmap(srcSize, CV_32FC1), ymap(srcSize, CV_32FC1);
213
214
{
215
Mat _xmap = xmap.getMat(ACCESS_WRITE), _ymap = ymap.getMat(ACCESS_WRITE);
216
for (int i = 0; i < srcSize.height; ++i)
217
{
218
float * const xmap_row = _xmap.ptr<float>(i);
219
float * const ymap_row = _ymap.ptr<float>(i);
220
221
for (int j = 0; j < srcSize.width; ++j)
222
{
223
xmap_row[j] = (j - srcSize.width * 0.5f) * 0.75f + srcSize.width * 0.5f;
224
ymap_row[j] = (i - srcSize.height * 0.5f) * 0.75f + srcSize.height * 0.5f;
225
}
226
}
227
}
228
declare.in(src, WARMUP_RNG).in(xmap, ymap, WARMUP_READ).out(dst);
229
230
OCL_TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
231
232
SANITY_CHECK_NOTHING();
233
}
234
235
} } // namespace opencv_test::ocl
236
237
#endif // HAVE_OPENCL
238
239