Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/perf/opencl/perf_imgproc.cpp
16344 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
namespace opencv_test {
51
namespace ocl {
52
53
///////////// equalizeHist ////////////////////////
54
55
typedef TestBaseWithParam<Size> EqualizeHistFixture;
56
57
OCL_PERF_TEST_P(EqualizeHistFixture, EqualizeHist, OCL_TEST_SIZES)
58
{
59
const Size srcSize = GetParam();
60
const double eps = 1;
61
62
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
63
64
UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
65
declare.in(src, WARMUP_RNG).out(dst);
66
67
OCL_TEST_CYCLE() cv::equalizeHist(src, dst);
68
69
SANITY_CHECK(dst, eps);
70
}
71
72
///////////// calcHist ////////////////////////
73
74
typedef TestBaseWithParam<Size> CalcHistFixture;
75
76
OCL_PERF_TEST_P(CalcHistFixture, CalcHist, OCL_TEST_SIZES)
77
{
78
const Size srcSize = GetParam();
79
80
const std::vector<int> channels(1, 0);
81
std::vector<float> ranges(2);
82
std::vector<int> histSize(1, 256);
83
ranges[0] = 0;
84
ranges[1] = 256;
85
86
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
87
88
UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1);
89
declare.in(src, WARMUP_RNG).out(hist);
90
91
OCL_TEST_CYCLE() cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
92
93
SANITY_CHECK(hist);
94
}
95
96
///////////// calcHist ////////////////////////
97
98
typedef TestBaseWithParam<Size> CalcBackProjFixture;
99
100
OCL_PERF_TEST_P(CalcBackProjFixture, CalcBackProj, OCL_TEST_SIZES)
101
{
102
const Size srcSize = GetParam();
103
104
const std::vector<int> channels(1, 0);
105
std::vector<float> ranges(2);
106
std::vector<int> histSize(1, 256);
107
ranges[0] = 0;
108
ranges[1] = 256;
109
110
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
111
112
UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1), dst(srcSize, CV_8UC1);
113
declare.in(src, WARMUP_RNG).out(hist);
114
115
cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
116
117
declare.in(src, WARMUP_RNG).out(dst);
118
OCL_TEST_CYCLE() cv::calcBackProject(std::vector<UMat>(1,src), channels, hist, dst, ranges, 1);
119
120
SANITY_CHECK_NOTHING();
121
}
122
123
124
/////////// CopyMakeBorder //////////////////////
125
126
CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101)
127
128
typedef tuple<Size, MatType, Border> CopyMakeBorderParamType;
129
typedef TestBaseWithParam<CopyMakeBorderParamType> CopyMakeBorderFixture;
130
131
OCL_PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,
132
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, Border::all()))
133
{
134
const CopyMakeBorderParamType params = GetParam();
135
const Size srcSize = get<0>(params);
136
const int type = get<1>(params), borderType = get<2>(params);
137
138
checkDeviceMaxMemoryAllocSize(srcSize, type);
139
140
UMat src(srcSize, type), dst;
141
const Size dstSize = srcSize + Size(12, 12);
142
dst.create(dstSize, type);
143
declare.in(src, WARMUP_RNG).out(dst);
144
145
OCL_TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
146
147
SANITY_CHECK(dst);
148
}
149
150
///////////// CornerMinEigenVal ////////////////////////
151
152
typedef Size_MatType CornerMinEigenValFixture;
153
154
OCL_PERF_TEST_P(CornerMinEigenValFixture, CornerMinEigenVal,
155
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
156
{
157
const Size_MatType_t params = GetParam();
158
const Size srcSize = get<0>(params);
159
const int type = get<1>(params), borderType = BORDER_REFLECT;
160
const int blockSize = 7, apertureSize = 1 + 2 * 3;
161
162
checkDeviceMaxMemoryAllocSize(srcSize, type);
163
164
UMat src(srcSize, type), dst(srcSize, CV_32FC1);
165
declare.in(src, WARMUP_RNG).out(dst);
166
167
OCL_TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
168
169
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
170
}
171
172
///////////// CornerHarris ////////////////////////
173
174
typedef Size_MatType CornerHarrisFixture;
175
176
OCL_PERF_TEST_P(CornerHarrisFixture, CornerHarris,
177
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
178
{
179
const Size_MatType_t params = GetParam();
180
const Size srcSize = get<0>(params);
181
const int type = get<1>(params), borderType = BORDER_REFLECT;
182
183
checkDeviceMaxMemoryAllocSize(srcSize, type);
184
185
UMat src(srcSize, type), dst(srcSize, CV_32FC1);
186
declare.in(src, WARMUP_RNG).out(dst);
187
188
OCL_TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);
189
190
SANITY_CHECK(dst, 5e-6, ERROR_RELATIVE);
191
}
192
193
///////////// PreCornerDetect ////////////////////////
194
195
typedef Size_MatType PreCornerDetectFixture;
196
197
OCL_PERF_TEST_P(PreCornerDetectFixture, PreCornerDetect,
198
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
199
{
200
const Size_MatType_t params = GetParam();
201
const Size srcSize = get<0>(params);
202
const int type = get<1>(params), borderType = BORDER_REFLECT;
203
204
checkDeviceMaxMemoryAllocSize(srcSize, type);
205
206
UMat src(srcSize, type), dst(srcSize, CV_32FC1);
207
declare.in(src, WARMUP_RNG).out(dst);
208
209
OCL_TEST_CYCLE() cv::preCornerDetect(src, dst, 3, borderType);
210
211
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
212
}
213
214
///////////// Integral ////////////////////////
215
216
typedef tuple<Size, MatDepth> IntegralParams;
217
typedef TestBaseWithParam<IntegralParams> IntegralFixture;
218
219
OCL_PERF_TEST_P(IntegralFixture, Integral1, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
220
{
221
const IntegralParams params = GetParam();
222
const Size srcSize = get<0>(params);
223
const int ddepth = get<1>(params);
224
225
checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
226
227
UMat src(srcSize, CV_8UC1), dst(srcSize + Size(1, 1), ddepth);
228
declare.in(src, WARMUP_RNG).out(dst);
229
230
OCL_TEST_CYCLE() cv::integral(src, dst, ddepth);
231
232
SANITY_CHECK(dst, 2e-6, ERROR_RELATIVE);
233
}
234
235
OCL_PERF_TEST_P(IntegralFixture, Integral2, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
236
{
237
const IntegralParams params = GetParam();
238
const Size srcSize = get<0>(params);
239
const int ddepth = get<1>(params);
240
241
checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
242
243
UMat src(srcSize, CV_8UC1), sum(srcSize + Size(1, 1), ddepth), sqsum(srcSize + Size(1, 1), CV_32F);
244
declare.in(src, WARMUP_RNG).out(sum, sqsum);
245
246
OCL_TEST_CYCLE() cv::integral(src, sum, sqsum, ddepth, CV_32F);
247
248
SANITY_CHECK(sum, 2e-4, ERROR_RELATIVE);
249
SANITY_CHECK(sqsum, 5e-5, ERROR_RELATIVE);
250
}
251
252
///////////// Threshold ////////////////////////
253
254
CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO_INV)
255
256
typedef tuple<Size, MatType, ThreshType> ThreshParams;
257
typedef TestBaseWithParam<ThreshParams> ThreshFixture;
258
259
OCL_PERF_TEST_P(ThreshFixture, Threshold,
260
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, ThreshType::all()))
261
{
262
const ThreshParams params = GetParam();
263
const Size srcSize = get<0>(params);
264
const int srcType = get<1>(params);
265
const int threshType = get<2>(params);
266
const double maxValue = 220.0, threshold = 50;
267
268
checkDeviceMaxMemoryAllocSize(srcSize, srcType);
269
270
UMat src(srcSize, srcType), dst(srcSize, srcType);
271
declare.in(src, WARMUP_RNG).out(dst);
272
273
OCL_TEST_CYCLE() cv::threshold(src, dst, threshold, maxValue, threshType);
274
275
SANITY_CHECK(dst);
276
}
277
278
///////////// CLAHE ////////////////////////
279
280
typedef TestBaseWithParam<Size> CLAHEFixture;
281
282
OCL_PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TEST_SIZES)
283
{
284
const Size srcSize = GetParam();
285
286
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
287
288
UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
289
const double clipLimit = 40.0;
290
declare.in(src, WARMUP_RNG).out(dst);
291
292
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
293
OCL_TEST_CYCLE() clahe->apply(src, dst);
294
295
SANITY_CHECK(dst);
296
}
297
298
///////////// Canny ////////////////////////
299
300
typedef tuple<Size, int, bool> CannyParams;
301
typedef TestBaseWithParam<CannyParams> CannyFixture;
302
303
OCL_PERF_TEST_P(CannyFixture, Canny, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(3, 5), Bool()))
304
{
305
const CannyParams& params = GetParam();
306
cv::Size imgSize = get<0>(params);
307
int apertureSize = get<1>(params);
308
bool L2Grad = get<2>(params);
309
310
Mat _img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);
311
ASSERT_TRUE(!_img.empty()) << "can't open aloe-L.png";
312
313
UMat img;
314
cv::resize(_img, img, imgSize, 0, 0, INTER_LINEAR_EXACT);
315
UMat edges(img.size(), CV_8UC1);
316
317
declare.in(img).out(edges);
318
319
PERF_SAMPLE_BEGIN();
320
cv::Canny(img, edges, 50.0, 100.0, apertureSize, L2Grad);
321
PERF_SAMPLE_END();
322
323
SANITY_CHECK_NOTHING();
324
}
325
326
} } // namespace opencv_test::ocl
327
328