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 // Shengen Yan, yanshengen@gmail.com
22 // Jiang Liyuan, lyuan001.good@163.com
23 // Rock Li, Rock.Li@amd.com
24 // Wu Zailong, bullet@yeah.net
25 // Xu Pang, pangxu010@163.com
26 // Sen Liu, swjtuls1987@126.com
28 // Redistribution and use in source and binary forms, with or without modification,
29 // are permitted provided that the following conditions are met:
31 // * Redistribution's of source code must retain the above copyright notice,
32 // this list of conditions and the following disclaimer.
34 // * Redistribution's in binary form must reproduce the above copyright notice,
35 // this list of conditions and the following disclaimer in the documentation
36 // and/or other materials provided with the distribution.
38 // * The name of the copyright holders may not be used to endorse or promote products
39 // derived from this software without specific prior written permission.
41 // This software is provided by the copyright holders and contributors "as is" and
42 // any express or implied warranties, including, but not limited to, the implied
43 // warranties of merchantability and fitness for a particular purpose are disclaimed.
44 // In no event shall the Intel Corporation or contributors be liable for any direct,
45 // indirect, incidental, special, exemplary, or consequential damages
46 // (including, but not limited to, procurement of substitute goods or services;
47 // loss of use, data, or profits; or business interruption) however caused
48 // and on any theory of liability, whether in contract, strict liability,
49 // or tort (including negligence or otherwise) arising in any way out of
50 // the use of this software, even if advised of the possibility of such damage.
54 #include "test_precomp.hpp"
56 #include "opencv2/ts/ocl_test.hpp"
63 ///////////////////////////////////////////////////////////////////////////////
65 PARAM_TEST_CASE(ImgprocTestBase, MatType,
70 int type, borderType, blockSize;
73 TEST_DECLARE_INPUT_PARAMETER(src);
74 TEST_DECLARE_OUTPUT_PARAMETER(dst);
79 blockSize = GET_PARAM(1);
80 borderType = GET_PARAM(2);
81 useRoi = GET_PARAM(3);
84 virtual void random_roi()
86 Size roiSize = randomSize(1, MAX_VALUE);
87 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
88 randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
90 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
91 randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
93 UMAT_UPLOAD_INPUT_PARAMETER(src);
94 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
97 void Near(double threshold = 0.0, bool relative = false)
100 OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
102 OCL_EXPECT_MATS_NEAR(dst, threshold);
106 //////////////////////////////// copyMakeBorder ////////////////////////////////////////////
108 PARAM_TEST_CASE(CopyMakeBorder, MatDepth, // depth
109 Channels, // channels
110 bool, // isolated or not
111 BorderType, // border type
114 int type, borderType;
117 TestUtils::Border border;
120 TEST_DECLARE_INPUT_PARAMETER(src);
121 TEST_DECLARE_OUTPUT_PARAMETER(dst);
125 type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
126 borderType = GET_PARAM(3);
129 borderType |= BORDER_ISOLATED;
131 useRoi = GET_PARAM(4);
136 border = randomBorder(0, MAX_VALUE << 2);
137 val = randomScalar(-MAX_VALUE, MAX_VALUE);
139 Size roiSize = randomSize(1, MAX_VALUE);
140 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
141 randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
143 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
144 dstBorder.top += border.top;
145 dstBorder.lef += border.lef;
146 dstBorder.rig += border.rig;
147 dstBorder.bot += border.bot;
149 randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
151 UMAT_UPLOAD_INPUT_PARAMETER(src);
152 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
157 OCL_EXPECT_MATS_NEAR(dst, 0);
161 OCL_TEST_P(CopyMakeBorder, Mat)
163 for (int i = 0; i < test_loop_times; ++i)
167 OCL_OFF(cv::copyMakeBorder(src_roi, dst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));
168 OCL_ON(cv::copyMakeBorder(usrc_roi, udst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));
174 //////////////////////////////// equalizeHist //////////////////////////////////////////////
176 typedef ImgprocTestBase EqualizeHist;
178 OCL_TEST_P(EqualizeHist, Mat)
180 for (int j = 0; j < test_loop_times; j++)
184 OCL_OFF(cv::equalizeHist(src_roi, dst_roi));
185 OCL_ON(cv::equalizeHist(usrc_roi, udst_roi));
191 //////////////////////////////// Corners test //////////////////////////////////////////
193 struct CornerTestBase :
194 public ImgprocTestBase
196 virtual void random_roi()
198 Mat image = readImageType("../gpu/stereobm/aloe-L.png", type);
199 ASSERT_FALSE(image.empty());
201 bool isFP = CV_MAT_DEPTH(type) >= CV_32F;
205 image.convertTo(image, -1, 1.0 / 255);
209 Size roiSize = image.size();
210 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
212 Size wholeSize = Size(roiSize.width + srcBorder.lef + srcBorder.rig, roiSize.height + srcBorder.top + srcBorder.bot);
213 src = randomMat(wholeSize, type, -val, val, false);
214 src_roi = src(Rect(srcBorder.lef, srcBorder.top, roiSize.width, roiSize.height));
215 image.copyTo(src_roi);
217 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
218 randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_32FC1, 5, 16);
220 UMAT_UPLOAD_INPUT_PARAMETER(src);
221 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
225 typedef CornerTestBase CornerMinEigenVal;
227 OCL_TEST_P(CornerMinEigenVal, Mat)
229 for (int j = 0; j < test_loop_times; j++)
233 int apertureSize = 3;
235 OCL_OFF(cv::cornerMinEigenVal(src_roi, dst_roi, blockSize, apertureSize, borderType));
236 OCL_ON(cv::cornerMinEigenVal(usrc_roi, udst_roi, blockSize, apertureSize, borderType));
242 //////////////////////////////// cornerHarris //////////////////////////////////////////
244 typedef CornerTestBase CornerHarris;
246 OCL_TEST_P(CornerHarris, Mat)
248 for (int j = 0; j < test_loop_times; j++)
252 int apertureSize = 3;
253 double k = randomDouble(0.01, 0.9);
255 OCL_OFF(cv::cornerHarris(src_roi, dst_roi, blockSize, apertureSize, k, borderType));
256 OCL_ON(cv::cornerHarris(usrc_roi, udst_roi, blockSize, apertureSize, k, borderType));
262 //////////////////////////////// preCornerDetect //////////////////////////////////////////
264 typedef ImgprocTestBase PreCornerDetect;
266 OCL_TEST_P(PreCornerDetect, Mat)
268 for (int j = 0; j < test_loop_times; j++)
272 const int apertureSize = blockSize;
274 OCL_OFF(cv::preCornerDetect(src_roi, dst_roi, apertureSize, borderType));
275 OCL_ON(cv::preCornerDetect(usrc_roi, udst_roi, apertureSize, borderType));
282 ////////////////////////////////// integral /////////////////////////////////////////////////
285 public ImgprocTestBase
289 TEST_DECLARE_OUTPUT_PARAMETER(dst2);
294 sdepth = GET_PARAM(1);
295 sqdepth = GET_PARAM(2);
296 useRoi = GET_PARAM(3);
299 virtual void random_roi()
301 ASSERT_EQ(CV_MAT_CN(type), 1);
303 Size roiSize = randomSize(1, MAX_VALUE), isize = Size(roiSize.width + 1, roiSize.height + 1);
304 Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
305 randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
307 Border dstBorder = randomBorder(0, useRoi ? 2 : 0);
308 randomSubMat(dst, dst_roi, isize, dstBorder, sdepth, 5, 16);
310 Border dst2Border = randomBorder(0, useRoi ? 2 : 0);
311 randomSubMat(dst2, dst2_roi, isize, dst2Border, sqdepth, 5, 16);
313 UMAT_UPLOAD_INPUT_PARAMETER(src);
314 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
315 UMAT_UPLOAD_OUTPUT_PARAMETER(dst2);
318 void Near2(double threshold = 0.0, bool relative = false)
321 OCL_EXPECT_MATS_NEAR_RELATIVE(dst2, threshold);
323 OCL_EXPECT_MATS_NEAR(dst2, threshold);
327 OCL_TEST_P(Integral, Mat1)
329 for (int j = 0; j < test_loop_times; j++)
333 OCL_OFF(cv::integral(src_roi, dst_roi, sdepth));
334 OCL_ON(cv::integral(usrc_roi, udst_roi, sdepth));
340 OCL_TEST_P(Integral, Mat2)
342 for (int j = 0; j < test_loop_times; j++)
346 OCL_OFF(cv::integral(src_roi, dst_roi, dst2_roi, sdepth, sqdepth));
347 OCL_ON(cv::integral(usrc_roi, udst_roi, udst2_roi, sdepth, sqdepth));
350 sqdepth == CV_32F ? Near2(2e-4, true) : Near2();
354 //////////////////////////////////////// threshold //////////////////////////////////////////////
357 public ImgprocTestBase
364 thresholdType = GET_PARAM(2);
365 useRoi = GET_PARAM(3);
369 OCL_TEST_P(Threshold, Mat)
371 for (int j = 0; j < test_loop_times; j++)
375 double maxVal = randomDouble(20.0, 127.0);
376 double thresh = randomDouble(0.0, maxVal);
378 OCL_OFF(cv::threshold(src_roi, dst_roi, thresh, maxVal, thresholdType));
379 OCL_ON(cv::threshold(usrc_roi, udst_roi, thresh, maxVal, thresholdType));
385 /////////////////////////////////////////// CLAHE //////////////////////////////////////////////////
387 PARAM_TEST_CASE(CLAHETest, Size, double, bool)
393 TEST_DECLARE_INPUT_PARAMETER(src);
394 TEST_DECLARE_OUTPUT_PARAMETER(dst);
398 gridSize = GET_PARAM(0);
399 clipLimit = GET_PARAM(1);
400 useRoi = GET_PARAM(2);
405 Size roiSize = randomSize(std::max(gridSize.height, gridSize.width), MAX_VALUE);
406 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
407 randomSubMat(src, src_roi, roiSize, srcBorder, CV_8UC1, 5, 256);
409 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
410 randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);
412 UMAT_UPLOAD_INPUT_PARAMETER(src);
413 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
416 void Near(double threshold = 0.0)
418 OCL_EXPECT_MATS_NEAR(dst, threshold);
422 OCL_TEST_P(CLAHETest, Accuracy)
424 for (int i = 0; i < test_loop_times; ++i)
428 Ptr<CLAHE> clahe = cv::createCLAHE(clipLimit, gridSize);
430 OCL_OFF(clahe->apply(src_roi, dst_roi));
431 OCL_ON(clahe->apply(usrc_roi, udst_roi));
437 /////////////////////////////////////////////////////////////////////////////////////
439 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine(
440 Values((MatType)CV_8UC1),
441 Values(0), // not used
442 Values(0), // not used
445 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine(
446 Values((MatType)CV_8UC1, (MatType)CV_32FC1),
448 Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
449 (BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT101),
452 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine(
453 Values((MatType)CV_8UC1, CV_32FC1),
455 Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
456 (BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
459 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, PreCornerDetect, Combine(
460 Values((MatType)CV_8UC1, CV_32FC1),
462 Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
463 (BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
466 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine(
467 Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F
468 Values(CV_32SC1, CV_32FC1), // desired sdepth
469 Values(CV_32FC1, CV_64FC1), // desired sqdepth
472 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
473 Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
474 CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,
475 CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4),
477 Values(ThreshOp(THRESH_BINARY),
478 ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),
479 ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),
482 OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CLAHETest, Combine(
483 Values(Size(4, 4), Size(32, 8), Size(8, 64)),
484 Values(0.0, 10.0, 62.0, 300.0),
487 OCL_INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(
488 testing::Values((MatDepth)CV_8U, (MatDepth)CV_16S, (MatDepth)CV_32S, (MatDepth)CV_32F),
489 testing::Values(Channels(1), Channels(3), (Channels)4),
490 Bool(), // border isolated or not
491 Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT,
492 (BorderType)BORDER_WRAP, (BorderType)BORDER_REFLECT_101),
495 } } // namespace cvtest::ocl
497 #endif // HAVE_OPENCL