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, 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. 17// 18// @Authors 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 27// 28// Redistribution and use in source and binary forms, with or without modification, 29// are permitted provided that the following conditions are met: 30// 31// * Redistribution's of source code must retain the above copyright notice, 32// this list of conditions and the following disclaimer. 33// 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. 37// 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. 40// 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. 51// 52//M*/ 53 54#include "../test_precomp.hpp" 55#include "opencv2/ts/ocl_test.hpp" 56 57#ifdef HAVE_OPENCL 58 59namespace cvtest { 60namespace ocl { 61 62enum 63{ 64 noType = -1 65}; 66 67///////////////////////////////////////////////////////////////////////////////////////////////// 68// warpAffine & warpPerspective 69 70PARAM_TEST_CASE(WarpTestBase, MatType, Interpolation, bool, bool) 71{ 72 int type, interpolation; 73 Size dsize; 74 bool useRoi, mapInverse; 75 int depth; 76 77 TEST_DECLARE_INPUT_PARAMETER(src); 78 TEST_DECLARE_OUTPUT_PARAMETER(dst); 79 80 virtual void SetUp() 81 { 82 type = GET_PARAM(0); 83 interpolation = GET_PARAM(1); 84 mapInverse = GET_PARAM(2); 85 useRoi = GET_PARAM(3); 86 depth = CV_MAT_DEPTH(type); 87 88 if (mapInverse) 89 interpolation |= WARP_INVERSE_MAP; 90 } 91 92 void random_roi() 93 { 94 dsize = randomSize(1, MAX_VALUE); 95 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); 99 100 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); 101 randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE); 102 103 UMAT_UPLOAD_INPUT_PARAMETER(src); 104 UMAT_UPLOAD_OUTPUT_PARAMETER(dst); 105 } 106 107 void Near(double threshold = 0.0) 108 { 109 if (depth < CV_32F) 110 EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold)); 111 else 112 OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold); 113 } 114}; 115 116/////warpAffine 117 118typedef WarpTestBase WarpAffine; 119 120OCL_TEST_P(WarpAffine, Mat) 121{ 122 for (int j = 0; j < test_loop_times; j++) 123 { 124 double eps = depth < CV_32F ? 0.04 : 0.06; 125 random_roi(); 126 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)); 129 130 OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation)); 131 OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation)); 132 133 Near(eps); 134 } 135} 136 137//// warpPerspective 138 139typedef WarpTestBase WarpPerspective; 140 141OCL_TEST_P(WarpPerspective, Mat) 142{ 143 for (int j = 0; j < test_loop_times; j++) 144 { 145 double eps = depth < CV_32F ? 0.03 : 0.06; 146 random_roi(); 147 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); 156 157 OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation)); 158 OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation)); 159 160 Near(eps); 161 } 162} 163 164 165///////////////////////////////////////////////////////////////////////////////////////////////// 166//// resize 167 168PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool, int) 169{ 170 int type, interpolation; 171 int widthMultiple; 172 double fx, fy; 173 bool useRoi; 174 175 TEST_DECLARE_INPUT_PARAMETER(src); 176 TEST_DECLARE_OUTPUT_PARAMETER(dst); 177 178 virtual void SetUp() 179 { 180 type = GET_PARAM(0); 181 fx = GET_PARAM(1); 182 fy = GET_PARAM(2); 183 interpolation = GET_PARAM(3); 184 useRoi = GET_PARAM(4); 185 widthMultiple = GET_PARAM(5); 186 } 187 188 void random_roi() 189 { 190 CV_Assert(fx > 0 && fy > 0); 191 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); 197 198 if (dstRoiSize.area() == 0) 199 { 200 random_roi(); 201 return; 202 } 203 204 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); 205 randomSubMat(src, src_roi, srcRoiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE); 206 207 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); 208 randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE); 209 210 UMAT_UPLOAD_INPUT_PARAMETER(src); 211 UMAT_UPLOAD_OUTPUT_PARAMETER(dst); 212 } 213 214 void Near(double threshold = 0.0) 215 { 216 OCL_EXPECT_MATS_NEAR(dst, threshold); 217 } 218}; 219 220OCL_TEST_P(Resize, Mat) 221{ 222 for (int j = 0; j < test_loop_times; j++) 223 { 224 int depth = CV_MAT_DEPTH(type); 225 double eps = depth <= CV_32S ? 1 : 5e-2; 226 227 random_roi(); 228 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)); 231 232 Near(eps); 233 } 234} 235 236///////////////////////////////////////////////////////////////////////////////////////////////// 237// remap 238 239PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair<MatType, MatType>, BorderType, bool) 240{ 241 int srcType, map1Type, map2Type; 242 int borderType; 243 bool useRoi; 244 245 Scalar val; 246 247 TEST_DECLARE_INPUT_PARAMETER(src); 248 TEST_DECLARE_INPUT_PARAMETER(map1); 249 TEST_DECLARE_INPUT_PARAMETER(map2); 250 TEST_DECLARE_OUTPUT_PARAMETER(dst); 251 252 virtual void SetUp() 253 { 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); 259 } 260 261 void random_roi() 262 { 263 val = randomScalar(-MAX_VALUE, MAX_VALUE); 264 Size srcROISize = randomSize(1, MAX_VALUE); 265 Size dstROISize = randomSize(1, MAX_VALUE); 266 267 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); 268 randomSubMat(src, src_roi, srcROISize, srcBorder, srcType, 5, 256); 269 270 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); 271 randomSubMat(dst, dst_roi, dstROISize, dstBorder, srcType, -MAX_VALUE, MAX_VALUE); 272 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); 276 277 Border map2Border = randomBorder(0, useRoi ? MAX_VALUE + 1 : 0); 278 if (map2Type != noType) 279 { 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); 284 } 285 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); 291 } 292 293 void Near(double threshold = 0.0) 294 { 295 OCL_EXPECT_MATS_NEAR(dst, threshold); 296 } 297}; 298 299typedef Remap Remap_INTER_NEAREST; 300 301OCL_TEST_P(Remap_INTER_NEAREST, Mat) 302{ 303 for (int j = 0; j < test_loop_times; j++) 304 { 305 random_roi(); 306 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)); 309 310 Near(1.0); 311 } 312} 313 314typedef Remap Remap_INTER_LINEAR; 315 316OCL_TEST_P(Remap_INTER_LINEAR, Mat) 317{ 318 for (int j = 0; j < test_loop_times; j++) 319 { 320 random_roi(); 321 322 double eps = 2.0; 323#ifdef ANDROID 324 // TODO investigate accuracy 325 if (cv::ocl::Device::getDefault().isNVidia()) 326 eps = 8.0; 327#endif 328 329 OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val)); 330 OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val)); 331 332 Near(eps); 333 } 334} 335 336///////////////////////////////////////////////////////////////////////////////////// 337 338OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine, Combine( 339 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), 340 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC), 341 Bool(), 342 Bool())); 343 344OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective, Combine( 345 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), 346 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC), 347 Bool(), 348 Bool())); 349 350OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Resize, Combine( 351 Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, CV_32FC4), 352 Values(0.5, 1.5, 2.0, 0.2), 353 Values(0.5, 1.5, 2.0, 0.2), 354 Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR), 355 Bool(), 356 Values(1, 16))); 357 358OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpResizeArea, Resize, Combine( 359 Values((MatType)CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), 360 Values(0.7, 0.4, 0.5), 361 Values(0.3, 0.6, 0.5), 362 Values((Interpolation)INTER_AREA), 363 Bool(), 364 Values(1, 16))); 365 366OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_LINEAR, Combine( 367 Values(CV_8U, CV_16U, CV_32F), 368 Values(1, 3, 4), 369 Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1), 370 std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1), 371 std::pair<MatType, MatType>((MatType)CV_32FC2, noType)), 372 Values((BorderType)BORDER_CONSTANT, 373 (BorderType)BORDER_REPLICATE, 374 (BorderType)BORDER_WRAP, 375 (BorderType)BORDER_REFLECT, 376 (BorderType)BORDER_REFLECT_101), 377 Bool())); 378 379OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_NEAREST, Combine( 380 Values(CV_8U, CV_16U, CV_32F), 381 Values(1, 3, 4), 382 Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1), 383 std::pair<MatType, MatType>((MatType)CV_32FC2, noType), 384 std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1), 385 std::pair<MatType, MatType>((MatType)CV_16SC2, noType)), 386 Values((BorderType)BORDER_CONSTANT, 387 (BorderType)BORDER_REPLICATE, 388 (BorderType)BORDER_WRAP, 389 (BorderType)BORDER_REFLECT, 390 (BorderType)BORDER_REFLECT_101), 391 Bool())); 392 393} } // namespace cvtest::ocl 394 395#endif // HAVE_OPENCL 396