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);
118 typedef WarpTestBase WarpAffine;
120 OCL_TEST_P(WarpAffine, Mat)
122 for (int j = 0; j < test_loop_times; j++)
124 double eps = depth < CV_32F ? 0.04 : 0.06;
127 Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
128 rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
130 OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
131 OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
139 typedef WarpTestBase WarpPerspective;
141 OCL_TEST_P(WarpPerspective, Mat)
143 for (int j = 0; j < test_loop_times; j++)
145 double eps = depth < CV_32F ? 0.03 : 0.06;
148 float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
149 float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
150 Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
151 Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
152 Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
153 Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
154 Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
155 Mat M = getPerspectiveTransform(sp, dp);
157 OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
158 OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
165 /////////////////////////////////////////////////////////////////////////////////////////////////
168 PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool, int)
170 int type, interpolation;
175 TEST_DECLARE_INPUT_PARAMETER(src);
176 TEST_DECLARE_OUTPUT_PARAMETER(dst);
183 interpolation = GET_PARAM(3);
184 useRoi = GET_PARAM(4);
185 widthMultiple = GET_PARAM(5);
190 CV_Assert(fx > 0 && fy > 0);
192 Size srcRoiSize = randomSize(10, MAX_VALUE), dstRoiSize;
193 // Make sure the width is a multiple of the requested value, and no more
194 srcRoiSize.width += widthMultiple - 1 - (srcRoiSize.width - 1) % widthMultiple;
195 dstRoiSize.width = cvRound(srcRoiSize.width * fx);
196 dstRoiSize.height = cvRound(srcRoiSize.height * fy);
198 if (dstRoiSize.area() == 0)
204 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
205 randomSubMat(src, src_roi, srcRoiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
207 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
208 randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
210 UMAT_UPLOAD_INPUT_PARAMETER(src);
211 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
214 void Near(double threshold = 0.0)
216 OCL_EXPECT_MATS_NEAR(dst, threshold);
220 OCL_TEST_P(Resize, Mat)
222 for (int j = 0; j < test_loop_times; j++)
224 int depth = CV_MAT_DEPTH(type);
225 double eps = depth <= CV_32S ? 1 : 5e-2;
229 OCL_OFF(cv::resize(src_roi, dst_roi, Size(), fx, fy, interpolation));
230 OCL_ON(cv::resize(usrc_roi, udst_roi, Size(), fx, fy, interpolation));
236 /////////////////////////////////////////////////////////////////////////////////////////////////
239 PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair<MatType, MatType>, BorderType, bool)
241 int srcType, map1Type, map2Type;
247 TEST_DECLARE_INPUT_PARAMETER(src);
248 TEST_DECLARE_INPUT_PARAMETER(map1);
249 TEST_DECLARE_INPUT_PARAMETER(map2);
250 TEST_DECLARE_OUTPUT_PARAMETER(dst);
254 srcType = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
255 map1Type = GET_PARAM(2).first;
256 map2Type = GET_PARAM(2).second;
257 borderType = GET_PARAM(3);
258 useRoi = GET_PARAM(4);
263 val = randomScalar(-MAX_VALUE, MAX_VALUE);
264 Size srcROISize = randomSize(1, MAX_VALUE);
265 Size dstROISize = randomSize(1, MAX_VALUE);
267 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
268 randomSubMat(src, src_roi, srcROISize, srcBorder, srcType, 5, 256);
270 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
271 randomSubMat(dst, dst_roi, dstROISize, dstBorder, srcType, -MAX_VALUE, MAX_VALUE);
273 int mapMaxValue = MAX_VALUE << 2;
274 Border map1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
275 randomSubMat(map1, map1_roi, dstROISize, map1Border, map1Type, -mapMaxValue, mapMaxValue);
277 Border map2Border = randomBorder(0, useRoi ? MAX_VALUE + 1 : 0);
278 if (map2Type != noType)
280 int mapMinValue = -mapMaxValue;
281 if (map2Type == CV_16UC1 || map2Type == CV_16SC1)
282 mapMinValue = 0, mapMaxValue = INTER_TAB_SIZE2;
283 randomSubMat(map2, map2_roi, dstROISize, map2Border, map2Type, mapMinValue, mapMaxValue);
286 UMAT_UPLOAD_INPUT_PARAMETER(src);
287 UMAT_UPLOAD_INPUT_PARAMETER(map1);
288 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
289 if (noType != map2Type)
290 UMAT_UPLOAD_INPUT_PARAMETER(map2);
293 void Near(double threshold = 0.0)
295 OCL_EXPECT_MATS_NEAR(dst, threshold);
299 typedef Remap Remap_INTER_NEAREST;
301 OCL_TEST_P(Remap_INTER_NEAREST, Mat)
303 for (int j = 0; j < test_loop_times; j++)
307 OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_NEAREST, borderType, val));
308 OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_NEAREST, borderType, val));
314 typedef Remap Remap_INTER_LINEAR;
316 OCL_TEST_P(Remap_INTER_LINEAR, Mat)
318 for (int j = 0; j < test_loop_times; j++)
322 OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val));
323 OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val));
329 /////////////////////////////////////////////////////////////////////////////////////
331 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine, Combine(
332 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
333 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
337 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective, Combine(
338 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
339 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
343 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Resize, Combine(
344 Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, CV_32FC4),
345 Values(0.5, 1.5, 2.0, 0.2),
346 Values(0.5, 1.5, 2.0, 0.2),
347 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR),
351 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpResizeArea, Resize, Combine(
352 Values((MatType)CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
353 Values(0.7, 0.4, 0.5),
354 Values(0.3, 0.6, 0.5),
355 Values((Interpolation)INTER_AREA),
359 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_LINEAR, Combine(
360 Values(CV_8U, CV_16U, CV_32F),
362 Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
363 std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
364 std::pair<MatType, MatType>((MatType)CV_32FC2, noType)),
365 Values((BorderType)BORDER_CONSTANT,
366 (BorderType)BORDER_REPLICATE,
367 (BorderType)BORDER_WRAP,
368 (BorderType)BORDER_REFLECT,
369 (BorderType)BORDER_REFLECT_101),
372 OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_NEAREST, Combine(
373 Values(CV_8U, CV_16U, CV_32F),
375 Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
376 std::pair<MatType, MatType>((MatType)CV_32FC2, noType),
377 std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
378 std::pair<MatType, MatType>((MatType)CV_16SC2, noType)),
379 Values((BorderType)BORDER_CONSTANT,
380 (BorderType)BORDER_REPLICATE,
381 (BorderType)BORDER_WRAP,
382 (BorderType)BORDER_REFLECT,
383 (BorderType)BORDER_REFLECT_101),
386 } } // namespace cvtest::ocl
388 #endif // HAVE_OPENCL