1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11
// For Open Source Computer Vision Library
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.
18
// Fangfang Bai, fangfang@multicorewareinc.com
19
// Jin Ma, jin@multicorewareinc.com
21
// Redistribution and use in source and binary forms, with or without modification,
22
// are permitted provided that the following conditions are met:
24
// * Redistribution's of source code must retain the above copyright notice,
25
// this list of conditions and the following disclaimer.
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.
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.
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.
47
#include "../perf_precomp.hpp"
48
#include "opencv2/ts/ocl_perf.hpp"
55
///////////// equalizeHist ////////////////////////
57
typedef TestBaseWithParam<Size> EqualizeHistFixture;
59
OCL_PERF_TEST_P(EqualizeHistFixture, EqualizeHist, OCL_TEST_SIZES)
61
const Size srcSize = GetParam();
64
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
66
UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
67
declare.in(src, WARMUP_RNG).out(dst);
69
OCL_TEST_CYCLE() cv::equalizeHist(src, dst);
71
SANITY_CHECK(dst, eps);
74
///////////// calcHist ////////////////////////
76
typedef TestBaseWithParam<Size> CalcHistFixture;
78
OCL_PERF_TEST_P(CalcHistFixture, CalcHist, OCL_TEST_SIZES)
80
const Size srcSize = GetParam();
82
const std::vector<int> channels(1, 0);
83
std::vector<float> ranges(2);
84
std::vector<int> histSize(1, 256);
88
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
90
UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1);
91
declare.in(src, WARMUP_RNG).out(hist);
93
OCL_TEST_CYCLE() cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
98
///////////// calcHist ////////////////////////
100
typedef TestBaseWithParam<Size> CalcBackProjFixture;
102
OCL_PERF_TEST_P(CalcBackProjFixture, CalcBackProj, OCL_TEST_SIZES)
104
const Size srcSize = GetParam();
106
const std::vector<int> channels(1, 0);
107
std::vector<float> ranges(2);
108
std::vector<int> histSize(1, 256);
112
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
114
UMat src(srcSize, CV_8UC1), hist(256, 1, CV_32FC1), dst(srcSize, CV_8UC1);
115
declare.in(src, WARMUP_RNG).out(hist);
117
cv::calcHist(std::vector<UMat>(1, src), channels, noArray(), hist, histSize, ranges, false);
119
declare.in(src, WARMUP_RNG).out(dst);
120
OCL_TEST_CYCLE() cv::calcBackProject(std::vector<UMat>(1,src), channels, hist, dst, ranges, 1);
122
SANITY_CHECK_NOTHING();
126
/////////// CopyMakeBorder //////////////////////
128
CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101)
130
typedef tuple<Size, MatType, Border> CopyMakeBorderParamType;
131
typedef TestBaseWithParam<CopyMakeBorderParamType> CopyMakeBorderFixture;
133
OCL_PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,
134
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, Border::all()))
136
const CopyMakeBorderParamType params = GetParam();
137
const Size srcSize = get<0>(params);
138
const int type = get<1>(params), borderType = get<2>(params);
140
checkDeviceMaxMemoryAllocSize(srcSize, type);
142
UMat src(srcSize, type), dst;
143
const Size dstSize = srcSize + Size(12, 12);
144
dst.create(dstSize, type);
145
declare.in(src, WARMUP_RNG).out(dst);
147
OCL_TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
152
///////////// CornerMinEigenVal ////////////////////////
154
typedef Size_MatType CornerMinEigenValFixture;
156
OCL_PERF_TEST_P(CornerMinEigenValFixture, CornerMinEigenVal,
157
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
159
const Size_MatType_t params = GetParam();
160
const Size srcSize = get<0>(params);
161
const int type = get<1>(params), borderType = BORDER_REFLECT;
162
const int blockSize = 7, apertureSize = 1 + 2 * 3;
164
checkDeviceMaxMemoryAllocSize(srcSize, type);
166
UMat src(srcSize, type), dst(srcSize, CV_32FC1);
167
declare.in(src, WARMUP_RNG).out(dst);
169
OCL_TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
171
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
174
///////////// CornerHarris ////////////////////////
176
typedef Size_MatType CornerHarrisFixture;
178
OCL_PERF_TEST_P(CornerHarrisFixture, CornerHarris,
179
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
181
const Size_MatType_t params = GetParam();
182
const Size srcSize = get<0>(params);
183
const int type = get<1>(params), borderType = BORDER_REFLECT;
185
checkDeviceMaxMemoryAllocSize(srcSize, type);
187
UMat src(srcSize, type), dst(srcSize, CV_32FC1);
188
declare.in(src, WARMUP_RNG).out(dst);
190
OCL_TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);
192
SANITY_CHECK(dst, 5e-6, ERROR_RELATIVE);
195
///////////// PreCornerDetect ////////////////////////
197
typedef Size_MatType PreCornerDetectFixture;
199
OCL_PERF_TEST_P(PreCornerDetectFixture, PreCornerDetect,
200
::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
202
const Size_MatType_t params = GetParam();
203
const Size srcSize = get<0>(params);
204
const int type = get<1>(params), borderType = BORDER_REFLECT;
206
checkDeviceMaxMemoryAllocSize(srcSize, type);
208
UMat src(srcSize, type), dst(srcSize, CV_32FC1);
209
declare.in(src, WARMUP_RNG).out(dst);
211
OCL_TEST_CYCLE() cv::preCornerDetect(src, dst, 3, borderType);
213
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
216
///////////// Integral ////////////////////////
218
typedef tuple<Size, MatDepth> IntegralParams;
219
typedef TestBaseWithParam<IntegralParams> IntegralFixture;
221
OCL_PERF_TEST_P(IntegralFixture, Integral1, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
223
const IntegralParams params = GetParam();
224
const Size srcSize = get<0>(params);
225
const int ddepth = get<1>(params);
227
checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
229
UMat src(srcSize, CV_8UC1), dst(srcSize + Size(1, 1), ddepth);
230
declare.in(src, WARMUP_RNG).out(dst);
232
OCL_TEST_CYCLE() cv::integral(src, dst, ddepth);
234
SANITY_CHECK(dst, 2e-6, ERROR_RELATIVE);
237
OCL_PERF_TEST_P(IntegralFixture, Integral2, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_32S, CV_32F)))
239
const IntegralParams params = GetParam();
240
const Size srcSize = get<0>(params);
241
const int ddepth = get<1>(params);
243
checkDeviceMaxMemoryAllocSize(srcSize, ddepth);
245
UMat src(srcSize, CV_8UC1), sum(srcSize + Size(1, 1), ddepth), sqsum(srcSize + Size(1, 1), CV_32F);
246
declare.in(src, WARMUP_RNG).out(sum, sqsum);
248
OCL_TEST_CYCLE() cv::integral(src, sum, sqsum, ddepth, CV_32F);
250
SANITY_CHECK(sum, 2e-4, ERROR_RELATIVE);
251
SANITY_CHECK(sqsum, 5e-5, ERROR_RELATIVE);
254
///////////// Threshold ////////////////////////
256
CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO_INV)
258
typedef tuple<Size, MatType, ThreshType> ThreshParams;
259
typedef TestBaseWithParam<ThreshParams> ThreshFixture;
261
OCL_PERF_TEST_P(ThreshFixture, Threshold,
262
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, ThreshType::all()))
264
const ThreshParams params = GetParam();
265
const Size srcSize = get<0>(params);
266
const int srcType = get<1>(params);
267
const int threshType = get<2>(params);
268
const double maxValue = 220.0, threshold = 50;
270
checkDeviceMaxMemoryAllocSize(srcSize, srcType);
272
UMat src(srcSize, srcType), dst(srcSize, srcType);
273
declare.in(src, WARMUP_RNG).out(dst);
275
OCL_TEST_CYCLE() cv::threshold(src, dst, threshold, maxValue, threshType);
280
///////////// CLAHE ////////////////////////
282
typedef TestBaseWithParam<Size> CLAHEFixture;
284
OCL_PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TEST_SIZES)
286
const Size srcSize = GetParam();
288
checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
290
UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
291
const double clipLimit = 40.0;
292
declare.in(src, WARMUP_RNG).out(dst);
294
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
295
OCL_TEST_CYCLE() clahe->apply(src, dst);
300
///////////// Canny ////////////////////////
302
typedef tuple<int, bool> CannyParams;
303
typedef TestBaseWithParam<CannyParams> CannyFixture;
305
OCL_PERF_TEST_P(CannyFixture, Canny, ::testing::Combine(OCL_PERF_ENUM(3, 5), Bool()))
307
const CannyParams params = GetParam();
308
int apertureSize = get<0>(params);
309
bool L2Grad = get<1>(params);
311
Mat _img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);
312
ASSERT_TRUE(!_img.empty()) << "can't open aloe-L.png";
316
UMat edges(img.size(), CV_8UC1);
318
declare.in(img, WARMUP_RNG).out(edges);
320
OCL_TEST_CYCLE() cv::Canny(img, edges, 50.0, 100.0, apertureSize, L2Grad);
322
if (apertureSize == 3)
325
SANITY_CHECK_NOTHING();
329
} } // namespace cvtest::ocl
331
#endif // HAVE_OPENCL