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, fangfang@multicorewareinc.com
19//    Jin Ma,       jin@multicorewareinc.com
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
52namespace cvtest {
53namespace ocl {
54
55typedef tuple<Size, MatType, int> FilterParams;
56typedef TestBaseWithParam<FilterParams> FilterFixture;
57
58///////////// Blur ////////////////////////
59
60typedef FilterFixture BlurFixture;
61
62OCL_PERF_TEST_P(BlurFixture, Blur,
63                ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5)))
64{
65    const FilterParams params = GetParam();
66    const Size srcSize = get<0>(params);
67    const int type = get<1>(params), ksize = get<2>(params), bordertype = BORDER_CONSTANT;
68    const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-5;
69
70    checkDeviceMaxMemoryAllocSize(srcSize, type);
71
72    UMat src(srcSize, type), dst(srcSize, type);
73    declare.in(src, WARMUP_RNG).out(dst);
74
75    OCL_TEST_CYCLE() cv::blur(src, dst, Size(ksize, ksize), Point(-1, -1), bordertype);
76
77    SANITY_CHECK(dst, eps);
78}
79
80///////////// SqrBoxFilter ////////////////////////
81
82typedef tuple<Size, MatType, Size> SqrBoxFilterParams;
83typedef TestBaseWithParam<SqrBoxFilterParams> SqrBoxFilterFixture;
84
85OCL_PERF_TEST_P(SqrBoxFilterFixture, SqrBoxFilter,
86                ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
87                                   OCL_PERF_ENUM(Size(3, 3), Size(20, 3), Size(3, 20), Size(20, 20))))
88{
89    const SqrBoxFilterParams params = GetParam();
90    const Size srcSize = get<0>(params), ksize = get<2>(params);
91    const int type = get<1>(params), depth = CV_MAT_DEPTH(type),
92            ddepth = depth == CV_8U ? CV_32S : CV_32F;
93    const double eps = ddepth == CV_32S ? 0 : 5e-5;
94
95    checkDeviceMaxMemoryAllocSize(srcSize, CV_MAKE_TYPE(ddepth, CV_MAT_CN(type)));
96
97    UMat src(srcSize, type), dst(srcSize, type);
98    declare.in(src, WARMUP_RNG).out(dst);
99
100    OCL_TEST_CYCLE() cv::sqrBoxFilter(src, dst, ddepth, ksize, Point(-1, -1), false);
101
102    SANITY_CHECK(dst, eps);
103}
104
105///////////// Laplacian////////////////////////
106
107typedef FilterFixture LaplacianFixture;
108
109OCL_PERF_TEST_P(LaplacianFixture, Laplacian,
110                ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5)))
111{
112    const FilterParams params = GetParam();
113    const Size srcSize = get<0>(params);
114    const int type = get<1>(params), ksize = get<2>(params);
115    const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 2e-5;
116
117    checkDeviceMaxMemoryAllocSize(srcSize, type);
118
119    UMat src(srcSize, type), dst(srcSize, type);
120    declare.in(src, WARMUP_RNG).out(dst);
121
122    OCL_TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize, 1);
123
124    SANITY_CHECK(dst, eps);
125}
126
127///////////// Erode ////////////////////
128
129typedef FilterFixture ErodeFixture;
130
131OCL_PERF_TEST_P(ErodeFixture, Erode,
132            ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5)))
133{
134    const FilterParams params = GetParam();
135    const Size srcSize = get<0>(params);
136    const int type = get<1>(params), ksize = get<2>(params);
137    const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize));
138
139    checkDeviceMaxMemoryAllocSize(srcSize, type);
140
141    UMat src(srcSize, type), dst(srcSize, type);
142    declare.in(src, WARMUP_RNG).out(dst).in(ker);
143
144    OCL_TEST_CYCLE() cv::erode(src, dst, ker);
145
146    SANITY_CHECK(dst);
147}
148
149///////////// Dilate ////////////////////
150
151typedef FilterFixture DilateFixture;
152
153OCL_PERF_TEST_P(DilateFixture, Dilate,
154            ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5)))
155{
156    const FilterParams params = GetParam();
157    const Size srcSize = get<0>(params);
158    const int type = get<1>(params), ksize = get<2>(params);
159    const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize));
160
161    checkDeviceMaxMemoryAllocSize(srcSize, type);
162
163    UMat src(srcSize, type), dst(srcSize, type);
164    declare.in(src, WARMUP_RNG).out(dst).in(ker);
165
166    OCL_TEST_CYCLE() cv::dilate(src, dst, ker);
167
168    SANITY_CHECK(dst);
169}
170
171///////////// MorphologyEx ////////////////////////
172
173CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT)
174
175typedef tuple<Size, MatType, MorphOp, int> MorphologyExParams;
176typedef TestBaseWithParam<MorphologyExParams> MorphologyExFixture;
177
178OCL_PERF_TEST_P(MorphologyExFixture, MorphologyEx,
179                ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, MorphOp::all(), OCL_PERF_ENUM(3, 5)))
180{
181    const MorphologyExParams params = GetParam();
182    const Size srcSize = get<0>(params);
183    const int type = get<1>(params), op = get<2>(params), ksize = get<3>(params);
184    const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize));
185
186    checkDeviceMaxMemoryAllocSize(srcSize, type);
187
188    UMat src(srcSize, type), dst(srcSize, type);
189    declare.in(src, WARMUP_RNG).out(dst).in(ker);
190
191    OCL_TEST_CYCLE() cv::morphologyEx(src, dst, op, ker);
192
193    SANITY_CHECK(dst);
194}
195
196///////////// Sobel ////////////////////////
197
198typedef Size_MatType SobelFixture;
199
200OCL_PERF_TEST_P(SobelFixture, Sobel,
201            ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
202{
203    const Size_MatType_t params = GetParam();
204    const Size srcSize = get<0>(params);
205    const int type = get<1>(params), dx = 1, dy = 1;
206
207    checkDeviceMaxMemoryAllocSize(srcSize, type, sizeof(float) * 2);
208
209    UMat src(srcSize, type), dst(srcSize, type);
210    declare.in(src, WARMUP_RNG).out(dst);
211
212    OCL_TEST_CYCLE() cv::Sobel(src, dst, -1, dx, dy);
213
214    SANITY_CHECK(dst, 1e-6);
215}
216
217///////////// Scharr ////////////////////////
218
219typedef Size_MatType ScharrFixture;
220
221OCL_PERF_TEST_P(ScharrFixture, Scharr,
222            ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES))
223{
224    const Size_MatType_t params = GetParam();
225    const Size srcSize = get<0>(params);
226    const int type = get<1>(params), dx = 1, dy = 0;
227    const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-5;
228
229    checkDeviceMaxMemoryAllocSize(srcSize, type, sizeof(float) * 2);
230
231    UMat src(srcSize, type), dst(srcSize, type);
232    declare.in(src, WARMUP_RNG).out(dst);
233
234    OCL_TEST_CYCLE() cv::Scharr(src, dst, -1, dx, dy);
235
236    SANITY_CHECK(dst, eps);
237}
238
239///////////// GaussianBlur ////////////////////////
240
241typedef FilterFixture GaussianBlurFixture;
242
243OCL_PERF_TEST_P(GaussianBlurFixture, GaussianBlur,
244            ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5, 7)))
245{
246    const FilterParams params = GetParam();
247    const Size srcSize = get<0>(params);
248    const int type = get<1>(params), ksize = get<2>(params);
249    const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 2 + DBL_EPSILON : 3e-4;
250
251    checkDeviceMaxMemoryAllocSize(srcSize, type);
252
253    UMat src(srcSize, type), dst(srcSize, type);
254    declare.in(src, WARMUP_RNG).out(dst);
255
256    OCL_TEST_CYCLE() cv::GaussianBlur(src, dst, Size(ksize, ksize), 1, 1, cv::BORDER_CONSTANT);
257
258    SANITY_CHECK(dst, eps);
259}
260
261///////////// Filter2D ////////////////////////
262
263typedef FilterFixture Filter2DFixture;
264
265OCL_PERF_TEST_P(Filter2DFixture, Filter2D,
266            ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, OCL_PERF_ENUM(3, 5)))
267{
268    const FilterParams params = GetParam();
269    const Size srcSize = get<0>(params);
270    const int type = get<1>(params), ksize = get<2>(params);
271    const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-5;
272
273    checkDeviceMaxMemoryAllocSize(srcSize, type);
274
275    UMat src(srcSize, type), dst(srcSize, type);
276    Mat kernel(ksize, ksize, CV_32SC1);
277    declare.in(src, WARMUP_RNG).in(kernel).out(dst);
278    randu(kernel, -3.0, 3.0);
279
280    OCL_TEST_CYCLE() cv::filter2D(src, dst, -1, kernel);
281
282    SANITY_CHECK(dst, eps);
283}
284
285///////////// Bilateral ////////////////////////
286
287typedef TestBaseWithParam<Size> BilateralFixture;
288
289OCL_PERF_TEST_P(BilateralFixture, Bilateral, OCL_TEST_SIZES)
290{
291    const Size srcSize = GetParam();
292    const int d = 7;
293    const double sigmacolor = 50.0, sigmaspace = 50.0;
294
295    checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
296
297    UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
298    declare.in(src, WARMUP_RNG).out(dst);
299
300    OCL_TEST_CYCLE() cv::bilateralFilter(src, dst, d, sigmacolor, sigmaspace);
301
302    SANITY_CHECK(dst);
303}
304
305///////////// MedianBlur ////////////////////////
306
307typedef tuple<Size, int> MedianBlurParams;
308typedef TestBaseWithParam<MedianBlurParams> MedianBlurFixture;
309
310OCL_PERF_TEST_P(MedianBlurFixture, Bilateral, ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(3, 5)))
311{
312    MedianBlurParams params = GetParam();
313    const Size srcSize = get<0>(params);
314    const int ksize = get<1>(params);
315
316    checkDeviceMaxMemoryAllocSize(srcSize, CV_8UC1);
317
318    UMat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
319    declare.in(src, WARMUP_RNG).out(dst);
320
321    OCL_TEST_CYCLE() cv::medianBlur(src, dst, ksize);
322
323    SANITY_CHECK(dst);
324}
325
326} } // namespace cvtest::ocl
327
328#endif // HAVE_OPENCL
329