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"
55 #include "opencv2/ts/ocl_test.hpp"
67 /////////////////////////////////////////////////////////////////////////////////////////////////
68 // warpAffine & warpPerspective
70 PARAM_TEST_CASE(WarpTestBase, MatType, Interpolation, bool, bool)
72 int type, interpolation;
74 bool useRoi, mapInverse;
77 TEST_DECLARE_INPUT_PARAMETER(src);
78 TEST_DECLARE_OUTPUT_PARAMETER(dst);
83 interpolation = GET_PARAM(1);
84 mapInverse = GET_PARAM(2);
85 useRoi = GET_PARAM(3);
86 depth = CV_MAT_DEPTH(type);
89 interpolation |= WARP_INVERSE_MAP;
94 dsize = randomSize(1, MAX_VALUE);
96 Size roiSize = randomSize(1, MAX_VALUE);
97 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
98 randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
100 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
101 randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
103 UMAT_UPLOAD_INPUT_PARAMETER(src);
104 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
107 void Near(double threshold = 0.0)
110 EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold));
112 OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
116 PARAM_TEST_CASE(WarpTest_cols4_Base, MatType, Interpolation, bool, bool)
118 int type, interpolation;
120 bool useRoi, mapInverse;
123 TEST_DECLARE_INPUT_PARAMETER(src);
124 TEST_DECLARE_OUTPUT_PARAMETER(dst);
129 interpolation = GET_PARAM(1);
130 mapInverse = GET_PARAM(2);
131 useRoi = GET_PARAM(3);
132 depth = CV_MAT_DEPTH(type);
135 interpolation |= WARP_INVERSE_MAP;
140 dsize = randomSize(1, MAX_VALUE);
141 dsize.width = ((dsize.width >> 2) + 1) * 4;
143 Size roiSize = randomSize(1, MAX_VALUE);
144 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
145 randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
147 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
148 randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
150 UMAT_UPLOAD_INPUT_PARAMETER(src);
151 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
154 void Near(double threshold = 0.0)
157 EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold));
159 OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
165 typedef WarpTestBase WarpAffine;
169 typedef WarpTestBase WarpAffine;
171 OCL_TEST_P(WarpAffine, Mat)
173 for (int j = 0; j < test_loop_times; j++)
175 double eps = depth < CV_32F ? 0.04 : 0.06;
178 Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
179 rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
181 OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
182 OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
188 typedef WarpTest_cols4_Base WarpAffine_cols4;
190 OCL_TEST_P(WarpAffine_cols4, Mat)
192 for (int j = 0; j < test_loop_times; j++)
194 double eps = depth < CV_32F ? 0.04 : 0.06;
197 Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
198 rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
200 OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
201 OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
209 typedef WarpTestBase WarpPerspective;
211 OCL_TEST_P(WarpPerspective, Mat)
213 for (int j = 0; j < test_loop_times; j++)
215 double eps = depth < CV_32F ? 0.03 : 0.06;
218 float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
219 float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
220 Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
221 Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
222 Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
223 Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
224 Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
225 Mat M = getPerspectiveTransform(sp, dp);
227 OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
228 OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
234 typedef WarpTest_cols4_Base WarpPerspective_cols4;
236 OCL_TEST_P(WarpPerspective_cols4, Mat)
238 for (int j = 0; j < test_loop_times; j++)
240 double eps = depth < CV_32F ? 0.03 : 0.06;
243 float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
244 float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
245 Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
246 Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
247 Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
248 Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
249 Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
250 Mat M = getPerspectiveTransform(sp, dp);
252 OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
253 OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
259 /////////////////////////////////////////////////////////////////////////////////////////////////
262 PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool, int)
264 int type, interpolation;
269 TEST_DECLARE_INPUT_PARAMETER(src);
270 TEST_DECLARE_OUTPUT_PARAMETER(dst);
277 interpolation = GET_PARAM(3);
278 useRoi = GET_PARAM(4);
279 widthMultiple = GET_PARAM(5);
284 CV_Assert(fx > 0 && fy > 0);
286 Size srcRoiSize = randomSize(10, MAX_VALUE), dstRoiSize;
287 // Make sure the width is a multiple of the requested value, and no more
288 srcRoiSize.width += widthMultiple - 1 - (srcRoiSize.width - 1) % widthMultiple;
289 dstRoiSize.width = cvRound(srcRoiSize.width * fx);
290 dstRoiSize.height = cvRound(srcRoiSize.height * fy);
292 if (dstRoiSize.area() == 0)
298 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
299 randomSubMat(src, src_roi, srcRoiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
301 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
302 randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
304 UMAT_UPLOAD_INPUT_PARAMETER(src);
305 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
308 void Near(double threshold = 0.0)
310 OCL_EXPECT_MATS_NEAR(dst, threshold);
314 OCL_TEST_P(Resize, Mat)
316 for (int j = 0; j < test_loop_times; j++)
318 int depth = CV_MAT_DEPTH(type);
319 double eps = depth <= CV_32S ? 1 : 5e-2;
323 OCL_OFF(cv::resize(src_roi, dst_roi, Size(), fx, fy, interpolation));
324 OCL_ON(cv::resize(usrc_roi, udst_roi, Size(), fx, fy, interpolation));
330 /////////////////////////////////////////////////////////////////////////////////////////////////
333 PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair<MatType, MatType>, BorderType, bool)
335 int srcType, map1Type, map2Type;
341 TEST_DECLARE_INPUT_PARAMETER(src);
342 TEST_DECLARE_INPUT_PARAMETER(map1);
343 TEST_DECLARE_INPUT_PARAMETER(map2);
344 TEST_DECLARE_OUTPUT_PARAMETER(dst);
348 srcType = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
349 map1Type = GET_PARAM(2).first;
350 map2Type = GET_PARAM(2).second;
351 borderType = GET_PARAM(3);
352 useRoi = GET_PARAM(4);
357 val = randomScalar(-MAX_VALUE, MAX_VALUE);
358 Size srcROISize = randomSize(1, MAX_VALUE);
359 Size dstROISize = randomSize(1, MAX_VALUE);
361 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
362 randomSubMat(src, src_roi, srcROISize, srcBorder, srcType, 5, 256);
364 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
365 randomSubMat(dst, dst_roi, dstROISize, dstBorder, srcType, -MAX_VALUE, MAX_VALUE);
367 int mapMaxValue = MAX_VALUE << 2;
368 Border map1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
369 randomSubMat(map1, map1_roi, dstROISize, map1Border, map1Type, -mapMaxValue, mapMaxValue);
371 Border map2Border = randomBorder(0, useRoi ? MAX_VALUE + 1 : 0);
372 if (map2Type != noType)
374 int mapMinValue = -mapMaxValue;
375 if (map2Type == CV_16UC1 || map2Type == CV_16SC1)
376 mapMinValue = 0, mapMaxValue = INTER_TAB_SIZE2;
377 randomSubMat(map2, map2_roi, dstROISize, map2Border, map2Type, mapMinValue, mapMaxValue);
380 UMAT_UPLOAD_INPUT_PARAMETER(src);
381 UMAT_UPLOAD_INPUT_PARAMETER(map1);
382 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
383 if (noType != map2Type)
384 UMAT_UPLOAD_INPUT_PARAMETER(map2);
387 void Near(double threshold = 0.0)
389 OCL_EXPECT_MATS_NEAR(dst, threshold);
393 typedef Remap Remap_INTER_NEAREST;
395 OCL_TEST_P(Remap_INTER_NEAREST, Mat)
397 for (int j = 0; j < test_loop_times; j++)
401 OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_NEAREST, borderType, val));
402 OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_NEAREST, borderType, val));
408 typedef Remap Remap_INTER_LINEAR;
410 OCL_TEST_P(Remap_INTER_LINEAR, Mat)
412 for (int j = 0; j < test_loop_times; j++)
418 // TODO investigate accuracy
419 if (cv::ocl::Device::getDefault().isNVidia())
423 OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val));
424 OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val));
430 /////////////////////////////////////////////////////////////////////////////////////
432 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine, Combine(
433 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
434 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
438 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine_cols4, Combine(
439 Values((MatType)CV_8UC1),
440 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR),
444 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective, Combine(
445 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
446 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
450 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective_cols4, Combine(
451 Values((MatType)CV_8UC1),
452 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR),
456 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Resize, Combine(
457 Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, CV_32FC4),
458 Values(0.5, 1.5, 2.0, 0.2),
459 Values(0.5, 1.5, 2.0, 0.2),
460 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR),
464 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpResizeArea, Resize, Combine(
465 Values((MatType)CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
466 Values(0.7, 0.4, 0.5),
467 Values(0.3, 0.6, 0.5),
468 Values((Interpolation)INTER_AREA),
472 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_LINEAR, Combine(
473 Values(CV_8U, CV_16U, CV_32F),
475 Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
476 std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
477 std::pair<MatType, MatType>((MatType)CV_32FC2, noType)),
478 Values((BorderType)BORDER_CONSTANT,
479 (BorderType)BORDER_REPLICATE,
480 (BorderType)BORDER_WRAP,
481 (BorderType)BORDER_REFLECT,
482 (BorderType)BORDER_REFLECT_101),
485 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_NEAREST, Combine(
486 Values(CV_8U, CV_16U, CV_32F),
488 Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
489 std::pair<MatType, MatType>((MatType)CV_32FC2, noType),
490 std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
491 std::pair<MatType, MatType>((MatType)CV_16SC2, noType)),
492 Values((BorderType)BORDER_CONSTANT,
493 (BorderType)BORDER_REPLICATE,
494 (BorderType)BORDER_WRAP,
495 (BorderType)BORDER_REFLECT,
496 (BorderType)BORDER_REFLECT_101),
499 } } // namespace cvtest::ocl
501 #endif // HAVE_OPENCL