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, Institute Of Software Chinese Academy Of Science, all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16 // Third party copyrights are property of their respective owners.
19 // Niko Li, newlife20080214@gmail.com
20 // Jia Haipeng, jiahaipeng95@gmail.com
21 // Zero Lin, Zero.Lin@amd.com
22 // Zhang Ying, zhangying913@gmail.com
23 // Yao Wang, bitwangyaoyao@gmail.com
25 // Redistribution and use in source and binary forms, with or without modification,
26 // are permitted provided that the following conditions are met:
28 // * Redistribution's of source code must retain the above copyright notice,
29 // this list of conditions and the following disclaimer.
31 // * Redistribution's in binary form must reproduce the above copyright notice,
32 // this list of conditions and the following disclaimer in the documentation
33 // and/or other materials provided with the distribution.
35 // * The name of the copyright holders may not be used to endorse or promote products
36 // derived from this software without specific prior written permission.
38 // This software is provided by the copyright holders and contributors "as is" and
39 // any express or implied warranties, including, but not limited to, the implied
40 // warranties of merchantability and fitness for a particular purpose are disclaimed.
41 // In no event shall the Intel Corporation or contributors be liable for any direct,
42 // indirect, incidental, special, exemplary, or consequential damages
43 // (including, but not limited to, procurement of substitute goods or services;
44 // loss of use, data, or profits; or business interruption) however caused
45 // and on any theory of liability, whether in contract, strict liability,
46 // or tort (including negligence or otherwise) arising in any way out of
47 // the use of this software, even if advised of the possibility of such damage.
51 #include "test_precomp.hpp"
53 #include "opencv2/ts/ocl_test.hpp"
60 PARAM_TEST_CASE(FilterTestBase, MatType,
63 BorderType, // border type
64 double, // optional parameter
66 int) // width multiplier
68 int type, borderType, ksize;
74 TEST_DECLARE_INPUT_PARAMETER(src);
75 TEST_DECLARE_OUTPUT_PARAMETER(dst);
82 borderType = GET_PARAM(3);
84 useRoi = GET_PARAM(5);
85 widthMultiple = GET_PARAM(6);
88 void random_roi(int minSize = 1)
93 Size roiSize = randomSize(minSize, MAX_VALUE);
94 roiSize.width &= ~((widthMultiple * 2) - 1);
95 roiSize.width += widthMultiple;
97 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
98 randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
100 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
101 randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -60, 70);
103 UMAT_UPLOAD_INPUT_PARAMETER(src);
104 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
109 int depth = CV_MAT_DEPTH(type);
110 bool isFP = depth >= CV_32F;
118 void Near(double threshold, bool relative)
121 OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
123 OCL_EXPECT_MATS_NEAR(dst, threshold);
127 ////////////////////////////////////////////////////////////////////////////////////////////////////
130 typedef FilterTestBase Bilateral;
132 OCL_TEST_P(Bilateral, Mat)
134 for (int j = 0; j < test_loop_times; j++)
138 double sigmacolor = rng.uniform(20, 100);
139 double sigmaspace = rng.uniform(10, 40);
141 OCL_OFF(cv::bilateralFilter(src_roi, dst_roi, ksize, sigmacolor, sigmaspace, borderType));
142 OCL_ON(cv::bilateralFilter(usrc_roi, udst_roi, ksize, sigmacolor, sigmaspace, borderType));
148 /////////////////////////////////////////////////////////////////////////////////////////////////
151 typedef FilterTestBase LaplacianTest;
153 OCL_TEST_P(LaplacianTest, Accuracy)
155 double scale = param;
157 for (int j = 0; j < test_loop_times; j++)
161 OCL_OFF(cv::Laplacian(src_roi, dst_roi, -1, ksize, scale, 10, borderType));
162 OCL_ON(cv::Laplacian(usrc_roi, udst_roi, -1, ksize, scale, 10, borderType));
169 /////////////////////////////////////////////////////////////////////////////////////////////////
172 typedef FilterTestBase SobelTest;
174 OCL_TEST_P(SobelTest, Mat)
176 int dx = size.width, dy = size.height;
177 double scale = param;
179 for (int j = 0; j < test_loop_times; j++)
183 OCL_OFF(cv::Sobel(src_roi, dst_roi, -1, dx, dy, ksize, scale, /* delta */0, borderType));
184 OCL_ON(cv::Sobel(usrc_roi, udst_roi, -1, dx, dy, ksize, scale, /* delta */0, borderType));
190 /////////////////////////////////////////////////////////////////////////////////////////////////
193 typedef FilterTestBase ScharrTest;
195 OCL_TEST_P(ScharrTest, Mat)
197 int dx = size.width, dy = size.height;
198 double scale = param;
200 for (int j = 0; j < test_loop_times; j++)
204 OCL_OFF(cv::Scharr(src_roi, dst_roi, -1, dx, dy, scale, /* delta */ 0, borderType));
205 OCL_ON(cv::Scharr(usrc_roi, udst_roi, -1, dx, dy, scale, /* delta */ 0, borderType));
211 /////////////////////////////////////////////////////////////////////////////////////////////////
214 typedef FilterTestBase GaussianBlurTest;
216 OCL_TEST_P(GaussianBlurTest, Mat)
218 for (int j = 0; j < test_loop_times + 1; j++)
222 double sigma1 = rng.uniform(0.1, 1.0);
223 double sigma2 = j % 2 == 0 ? sigma1 : rng.uniform(0.1, 1.0);
225 OCL_OFF(cv::GaussianBlur(src_roi, dst_roi, Size(ksize, ksize), sigma1, sigma2, borderType));
226 OCL_ON(cv::GaussianBlur(usrc_roi, udst_roi, Size(ksize, ksize), sigma1, sigma2, borderType));
228 Near(CV_MAT_DEPTH(type) >= CV_32F ? 5e-5 : 1, false);
232 /////////////////////////////////////////////////////////////////////////////////////////////////
235 typedef FilterTestBase Erode;
237 OCL_TEST_P(Erode, Mat)
239 Size kernelSize(ksize, ksize);
240 int iterations = (int)param;
242 for (int j = 0; j < test_loop_times; j++)
245 Mat kernel = randomMat(kernelSize, CV_8UC1, 0, 3);
247 OCL_OFF(cv::erode(src_roi, dst_roi, kernel, Point(-1, -1), iterations) );
248 OCL_ON(cv::erode(usrc_roi, udst_roi, kernel, Point(-1, -1), iterations) );
254 /////////////////////////////////////////////////////////////////////////////////////////////////
257 typedef FilterTestBase Dilate;
259 OCL_TEST_P(Dilate, Mat)
261 Size kernelSize(ksize, ksize);
262 int iterations = (int)param;
264 for (int j = 0; j < test_loop_times; j++)
267 Mat kernel = randomMat(kernelSize, CV_8UC1, 0, 3);
269 OCL_OFF(cv::dilate(src_roi, dst_roi, kernel, Point(-1, -1), iterations) );
270 OCL_ON(cv::dilate(usrc_roi, udst_roi, kernel, Point(-1, -1), iterations) );
276 /////////////////////////////////////////////////////////////////////////////////////////////////
279 typedef FilterTestBase MorphologyEx;
281 OCL_TEST_P(MorphologyEx, Mat)
283 Size kernelSize(ksize, ksize);
284 int iterations = (int)param;
285 int op = size.height;
287 for (int j = 0; j < test_loop_times; j++)
290 Mat kernel = randomMat(kernelSize, CV_8UC1, 0, 3);
292 OCL_OFF(cv::morphologyEx(src_roi, dst_roi, op, kernel, Point(-1, -1), iterations) );
293 OCL_ON(cv::morphologyEx(usrc_roi, udst_roi, op, kernel, Point(-1, -1), iterations) );
299 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
301 #define FILTER_BORDER_SET_NO_ISOLATED \
302 Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT, (BorderType)BORDER_WRAP, (BorderType)BORDER_REFLECT_101/*, \
303 (int)BORDER_CONSTANT|BORDER_ISOLATED, (int)BORDER_REPLICATE|BORDER_ISOLATED, \
304 (int)BORDER_REFLECT|BORDER_ISOLATED, (int)BORDER_WRAP|BORDER_ISOLATED, \
305 (int)BORDER_REFLECT_101|BORDER_ISOLATED*/) // WRAP and ISOLATED are not supported by cv:: version
307 #define FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED \
308 Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT, /*(int)BORDER_WRAP,*/ (BorderType)BORDER_REFLECT_101/*, \
309 (int)BORDER_CONSTANT|BORDER_ISOLATED, (int)BORDER_REPLICATE|BORDER_ISOLATED, \
310 (int)BORDER_REFLECT|BORDER_ISOLATED, (int)BORDER_WRAP|BORDER_ISOLATED, \
311 (int)BORDER_REFLECT_101|BORDER_ISOLATED*/) // WRAP and ISOLATED are not supported by cv:: version
313 #define FILTER_TYPES Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4)
315 OCL_INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine(
316 Values(CV_8UC1, CV_8UC3),
317 Values(5, 9), // kernel size
318 Values(Size(0, 0)), // not used
319 FILTER_BORDER_SET_NO_ISOLATED,
320 Values(0.0), // not used
324 OCL_INSTANTIATE_TEST_CASE_P(Filter, LaplacianTest, Combine(
326 Values(1, 3, 5), // kernel size
327 Values(Size(0, 0)), // not used
328 FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
329 Values(1.0, 0.2, 3.0), // kernel scale
331 Values(1))); // not used
333 OCL_INSTANTIATE_TEST_CASE_P(Filter, SobelTest, Combine(
335 Values(3, 5), // kernel size
336 Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)), // dx, dy
337 FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
338 Values(0.0), // not used
340 Values(1))); // not used
342 OCL_INSTANTIATE_TEST_CASE_P(Filter, ScharrTest, Combine(
344 Values(0), // not used
345 Values(Size(0, 1), Size(1, 0)), // dx, dy
346 FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
347 Values(1.0, 0.2), // kernel scale
349 Values(1))); // not used
351 OCL_INSTANTIATE_TEST_CASE_P(Filter, GaussianBlurTest, Combine(
353 Values(3, 5), // kernel size
354 Values(Size(0, 0)), // not used
355 FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
356 Values(0.0), // not used
358 Values(1))); // not used
360 OCL_INSTANTIATE_TEST_CASE_P(Filter, Erode, Combine(
361 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4, CV_64FC1, CV_64FC4),
363 Values(Size(0, 0)), //not used
364 Values((BorderType)BORDER_CONSTANT),
365 Values(1.0, 2.0, 3.0),
367 Values(1))); // not used
369 OCL_INSTANTIATE_TEST_CASE_P(Filter, Dilate, Combine(
370 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4, CV_64FC1, CV_64FC4),
372 Values(Size(0, 0)), // not used
373 Values((BorderType)BORDER_CONSTANT),
374 Values(1.0, 2.0, 3.0),
376 Values(1))); // not used
378 OCL_INSTANTIATE_TEST_CASE_P(Filter, MorphologyEx, Combine(
379 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
381 Values(Size(0, 2), Size(0, 3), Size(0, 4), Size(0, 5), Size(0, 6)), // used as generator of operations
382 Values((BorderType)BORDER_CONSTANT),
383 Values(1.0, 2.0, 3.0),
385 Values(1))); // not used
388 } } // namespace cvtest::ocl
390 #endif // HAVE_OPENCL