test_warp.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. #include "../test_precomp.hpp"
  54. #include "opencv2/ts/ocl_test.hpp"
  55. #ifdef HAVE_OPENCL
  56. namespace opencv_test {
  57. namespace ocl {
  58. enum
  59. {
  60. noType = -1
  61. };
  62. /////////////////////////////////////////////////////////////////////////////////////////////////
  63. // warpAffine & warpPerspective
  64. PARAM_TEST_CASE(WarpTestBase, MatType, Interpolation, bool, bool)
  65. {
  66. int type, interpolation;
  67. Size dsize;
  68. bool useRoi, mapInverse;
  69. int depth;
  70. TEST_DECLARE_INPUT_PARAMETER(src);
  71. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  72. virtual void SetUp()
  73. {
  74. type = GET_PARAM(0);
  75. interpolation = GET_PARAM(1);
  76. mapInverse = GET_PARAM(2);
  77. useRoi = GET_PARAM(3);
  78. depth = CV_MAT_DEPTH(type);
  79. if (mapInverse)
  80. interpolation |= WARP_INVERSE_MAP;
  81. }
  82. void random_roi()
  83. {
  84. dsize = randomSize(1, MAX_VALUE);
  85. Size roiSize = randomSize(1, MAX_VALUE);
  86. Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  87. randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
  88. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  89. randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
  90. UMAT_UPLOAD_INPUT_PARAMETER(src);
  91. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  92. }
  93. void Near(double threshold = 0.0)
  94. {
  95. if (depth < CV_32F)
  96. EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold));
  97. else
  98. OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
  99. }
  100. };
  101. PARAM_TEST_CASE(WarpTest_cols4_Base, MatType, Interpolation, bool, bool)
  102. {
  103. int type, interpolation;
  104. Size dsize;
  105. bool useRoi, mapInverse;
  106. int depth;
  107. TEST_DECLARE_INPUT_PARAMETER(src);
  108. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  109. virtual void SetUp()
  110. {
  111. type = GET_PARAM(0);
  112. interpolation = GET_PARAM(1);
  113. mapInverse = GET_PARAM(2);
  114. useRoi = GET_PARAM(3);
  115. depth = CV_MAT_DEPTH(type);
  116. if (mapInverse)
  117. interpolation |= WARP_INVERSE_MAP;
  118. }
  119. void random_roi()
  120. {
  121. dsize = randomSize(1, MAX_VALUE);
  122. dsize.width = ((dsize.width >> 2) + 1) * 4;
  123. Size roiSize = randomSize(1, MAX_VALUE);
  124. Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  125. randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
  126. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  127. randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
  128. UMAT_UPLOAD_INPUT_PARAMETER(src);
  129. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  130. }
  131. void Near(double threshold = 0.0)
  132. {
  133. if (depth < CV_32F)
  134. EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold));
  135. else
  136. OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
  137. }
  138. };
  139. /////warpAffine
  140. typedef WarpTestBase WarpAffine;
  141. /////warpAffine
  142. typedef WarpTestBase WarpAffine;
  143. OCL_TEST_P(WarpAffine, Mat)
  144. {
  145. for (int j = 0; j < test_loop_times; j++)
  146. {
  147. double eps = depth < CV_32F ? 0.04 : 0.06;
  148. random_roi();
  149. Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
  150. rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
  151. OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
  152. OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
  153. Near(eps);
  154. }
  155. }
  156. OCL_TEST_P(WarpAffine, inplace_25853) // when src and dst are the same variable, ocl on/off should produce consistent and correct results
  157. {
  158. for (int j = 0; j < test_loop_times; j++)
  159. {
  160. double eps = depth < CV_32F ? 0.04 : 0.06;
  161. random_roi();
  162. Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
  163. rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
  164. OCL_OFF(cv::warpAffine(src_roi, src_roi, M, dsize, interpolation));
  165. OCL_ON(cv::warpAffine(usrc_roi, usrc_roi, M, dsize, interpolation));
  166. dst_roi = src_roi.clone();
  167. udst_roi = usrc_roi.clone();
  168. Near(eps);
  169. }
  170. }
  171. typedef WarpTest_cols4_Base WarpAffine_cols4;
  172. OCL_TEST_P(WarpAffine_cols4, Mat)
  173. {
  174. for (int j = 0; j < test_loop_times; j++)
  175. {
  176. double eps = depth < CV_32F ? 0.04 : 0.06;
  177. random_roi();
  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));
  180. OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
  181. OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
  182. Near(eps);
  183. }
  184. }
  185. //// warpPerspective
  186. typedef WarpTestBase WarpPerspective;
  187. OCL_TEST_P(WarpPerspective, Mat)
  188. {
  189. for (int j = 0; j < test_loop_times; j++)
  190. {
  191. double eps = depth < CV_32F ? 0.03 : 0.06;
  192. random_roi();
  193. float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
  194. float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
  195. Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
  196. Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
  197. Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
  198. Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
  199. Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
  200. Mat M = getPerspectiveTransform(sp, dp);
  201. OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
  202. OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
  203. Near(eps);
  204. }
  205. }
  206. typedef WarpTest_cols4_Base WarpPerspective_cols4;
  207. OCL_TEST_P(WarpPerspective_cols4, Mat)
  208. {
  209. for (int j = 0; j < test_loop_times; j++)
  210. {
  211. double eps = depth < CV_32F ? 0.03 : 0.06;
  212. random_roi();
  213. float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
  214. float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
  215. Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
  216. Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
  217. Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
  218. Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
  219. Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
  220. Mat M = getPerspectiveTransform(sp, dp);
  221. OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
  222. OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
  223. Near(eps);
  224. }
  225. }
  226. /////////////////////////////////////////////////////////////////////////////////////////////////
  227. //// resize
  228. PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool, int)
  229. {
  230. int type, interpolation;
  231. int widthMultiple;
  232. double fx, fy;
  233. bool useRoi;
  234. TEST_DECLARE_INPUT_PARAMETER(src);
  235. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  236. virtual void SetUp()
  237. {
  238. type = GET_PARAM(0);
  239. fx = GET_PARAM(1);
  240. fy = GET_PARAM(2);
  241. interpolation = GET_PARAM(3);
  242. useRoi = GET_PARAM(4);
  243. widthMultiple = GET_PARAM(5);
  244. }
  245. void random_roi()
  246. {
  247. CV_Assert(fx > 0 && fy > 0);
  248. Size srcRoiSize = randomSize(10, MAX_VALUE), dstRoiSize;
  249. // Make sure the width is a multiple of the requested value, and no more
  250. srcRoiSize.width += widthMultiple - 1 - (srcRoiSize.width - 1) % widthMultiple;
  251. dstRoiSize.width = cvRound(srcRoiSize.width * fx);
  252. dstRoiSize.height = cvRound(srcRoiSize.height * fy);
  253. if (dstRoiSize.empty())
  254. {
  255. random_roi();
  256. return;
  257. }
  258. Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  259. randomSubMat(src, src_roi, srcRoiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
  260. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  261. randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
  262. UMAT_UPLOAD_INPUT_PARAMETER(src);
  263. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  264. }
  265. };
  266. #if defined(__aarch64__) || defined(__arm__)
  267. const int integerEps = 3;
  268. #else
  269. const int integerEps = 1;
  270. #endif
  271. OCL_TEST_P(Resize, Mat)
  272. {
  273. for (int j = 0; j < test_loop_times; j++)
  274. {
  275. int depth = CV_MAT_DEPTH(type);
  276. double eps = depth <= CV_32S ? integerEps : 5e-2;
  277. random_roi();
  278. OCL_OFF(cv::resize(src_roi, dst_roi, Size(), fx, fy, interpolation));
  279. OCL_ON(cv::resize(usrc_roi, udst_roi, Size(), fx, fy, interpolation));
  280. OCL_EXPECT_MAT_N_DIFF(dst, eps);
  281. }
  282. }
  283. OCL_TEST(Resize, overflow_21198)
  284. {
  285. Mat src(Size(600, 600), CV_16UC3, Scalar::all(32768));
  286. UMat src_u;
  287. src.copyTo(src_u);
  288. Mat dst;
  289. cv::resize(src, dst, Size(1024, 1024), 0, 0, INTER_LINEAR);
  290. UMat dst_u;
  291. cv::resize(src_u, dst_u, Size(1024, 1024), 0, 0, INTER_LINEAR);
  292. EXPECT_LE(cv::norm(dst_u, dst, NORM_INF), 1.0f);
  293. }
  294. /////////////////////////////////////////////////////////////////////////////////////////////////
  295. // remap
  296. PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair<MatType, MatType>, BorderType, bool)
  297. {
  298. int srcType, map1Type, map2Type;
  299. int borderType;
  300. bool useRoi;
  301. Scalar val;
  302. TEST_DECLARE_INPUT_PARAMETER(src);
  303. TEST_DECLARE_INPUT_PARAMETER(map1);
  304. TEST_DECLARE_INPUT_PARAMETER(map2);
  305. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  306. virtual void SetUp()
  307. {
  308. srcType = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
  309. map1Type = GET_PARAM(2).first;
  310. map2Type = GET_PARAM(2).second;
  311. borderType = GET_PARAM(3);
  312. useRoi = GET_PARAM(4);
  313. }
  314. void random_roi()
  315. {
  316. val = randomScalar(-MAX_VALUE, MAX_VALUE);
  317. Size srcROISize = randomSize(1, MAX_VALUE);
  318. Size dstROISize = randomSize(1, MAX_VALUE);
  319. Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  320. randomSubMat(src, src_roi, srcROISize, srcBorder, srcType, 5, 256);
  321. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  322. randomSubMat(dst, dst_roi, dstROISize, dstBorder, srcType, -MAX_VALUE, MAX_VALUE);
  323. int mapMaxValue = MAX_VALUE << 2;
  324. Border map1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  325. randomSubMat(map1, map1_roi, dstROISize, map1Border, map1Type, -mapMaxValue, mapMaxValue);
  326. Border map2Border = randomBorder(0, useRoi ? MAX_VALUE + 1 : 0);
  327. if (map2Type != noType)
  328. {
  329. int mapMinValue = -mapMaxValue;
  330. if (map2Type == CV_16UC1 || map2Type == CV_16SC1)
  331. mapMinValue = 0, mapMaxValue = INTER_TAB_SIZE2;
  332. randomSubMat(map2, map2_roi, dstROISize, map2Border, map2Type, mapMinValue, mapMaxValue);
  333. }
  334. UMAT_UPLOAD_INPUT_PARAMETER(src);
  335. UMAT_UPLOAD_INPUT_PARAMETER(map1);
  336. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  337. if (noType != map2Type)
  338. UMAT_UPLOAD_INPUT_PARAMETER(map2);
  339. }
  340. };
  341. typedef Remap Remap_INTER_NEAREST;
  342. OCL_TEST_P(Remap_INTER_NEAREST, Mat)
  343. {
  344. for (int j = 0; j < test_loop_times; j++)
  345. {
  346. random_roi();
  347. OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_NEAREST, borderType, val));
  348. OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_NEAREST, borderType, val));
  349. OCL_EXPECT_MAT_N_DIFF(dst, 1.0);
  350. }
  351. }
  352. typedef Remap Remap_INTER_LINEAR;
  353. OCL_TEST_P(Remap_INTER_LINEAR, Mat)
  354. {
  355. for (int j = 0; j < test_loop_times; j++)
  356. {
  357. random_roi();
  358. double eps = 2.0;
  359. #ifdef __ANDROID__
  360. // TODO investigate accuracy
  361. if (cv::ocl::Device::getDefault().isNVidia())
  362. eps = 8.0;
  363. #elif defined(__arm__)
  364. eps = 8.0;
  365. #endif
  366. OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val));
  367. OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val));
  368. OCL_EXPECT_MAT_N_DIFF(dst, eps);
  369. }
  370. }
  371. /////////////////////////////////////////////////////////////////////////////////////////////////
  372. // remap relative
  373. PARAM_TEST_CASE(RemapRelative, MatDepth, Channels, Interpolation, BorderType, bool)
  374. {
  375. int srcType;
  376. int interpolation;
  377. int borderType;
  378. bool useFixedPoint;
  379. Scalar val;
  380. TEST_DECLARE_INPUT_PARAMETER(map1);
  381. TEST_DECLARE_INPUT_PARAMETER(map2);
  382. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  383. UMat uSrc;
  384. UMat uMapRelativeX32F;
  385. UMat uMapRelativeY32F;
  386. UMat uMapAbsoluteX32F;
  387. UMat uMapAbsoluteY32F;
  388. UMat uMapRelativeX16S;
  389. UMat uMapRelativeY16S;
  390. UMat uMapAbsoluteX16S;
  391. UMat uMapAbsoluteY16S;
  392. virtual void SetUp()
  393. {
  394. srcType = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
  395. interpolation = GET_PARAM(2);
  396. borderType = GET_PARAM(3);
  397. useFixedPoint = GET_PARAM(4);
  398. const int nChannels = CV_MAT_CN(srcType);
  399. const cv::Size size(127, 61);
  400. cv::Mat data64FC1(1, size.area()*nChannels, CV_64FC1);
  401. data64FC1.forEach<double>([&](double& pixel, const int* position) {pixel = static_cast<double>(position[1]);});
  402. cv::Mat src;
  403. data64FC1.reshape(nChannels, size.height).convertTo(src, srcType);
  404. cv::Mat mapRelativeX32F(size, CV_32FC1);
  405. mapRelativeX32F.setTo(cv::Scalar::all(-0.25));
  406. cv::Mat mapRelativeY32F(size, CV_32FC1);
  407. mapRelativeY32F.setTo(cv::Scalar::all(-0.25));
  408. cv::Mat mapAbsoluteX32F = mapRelativeX32F.clone();
  409. mapAbsoluteX32F.forEach<float>([&](float& pixel, const int* position) {
  410. pixel += static_cast<float>(position[1]);
  411. });
  412. cv::Mat mapAbsoluteY32F = mapRelativeY32F.clone();
  413. mapAbsoluteY32F.forEach<float>([&](float& pixel, const int* position) {
  414. pixel += static_cast<float>(position[0]);
  415. });
  416. OCL_ON(src.copyTo(uSrc));
  417. OCL_ON(mapRelativeX32F.copyTo(uMapRelativeX32F));
  418. OCL_ON(mapRelativeY32F.copyTo(uMapRelativeY32F));
  419. OCL_ON(mapAbsoluteX32F.copyTo(uMapAbsoluteX32F));
  420. OCL_ON(mapAbsoluteY32F.copyTo(uMapAbsoluteY32F));
  421. if (useFixedPoint)
  422. {
  423. const bool nninterpolation = (interpolation == cv::INTER_NEAREST) || (interpolation == cv::INTER_NEAREST_EXACT);
  424. OCL_ON(cv::convertMaps(uMapAbsoluteX32F, uMapAbsoluteY32F, uMapAbsoluteX16S, uMapAbsoluteY16S, CV_16SC2, nninterpolation));
  425. OCL_ON(cv::convertMaps(uMapRelativeX32F, uMapRelativeY32F, uMapRelativeX16S, uMapRelativeY16S, CV_16SC2, nninterpolation));
  426. }
  427. }
  428. };
  429. OCL_TEST_P(RemapRelative, Mat)
  430. {
  431. cv::UMat uDstAbsolute;
  432. cv::UMat uDstRelative;
  433. if (useFixedPoint)
  434. {
  435. OCL_ON(cv::remap(uSrc, uDstAbsolute, uMapAbsoluteX16S, uMapAbsoluteY16S, interpolation, borderType));
  436. OCL_ON(cv::remap(uSrc, uDstRelative, uMapRelativeX16S, uMapRelativeY16S, interpolation | WARP_RELATIVE_MAP, borderType));
  437. }
  438. else
  439. {
  440. OCL_ON(cv::remap(uSrc, uDstAbsolute, uMapAbsoluteX32F, uMapAbsoluteY32F, interpolation, borderType));
  441. OCL_ON(cv::remap(uSrc, uDstRelative, uMapRelativeX32F, uMapRelativeY32F, interpolation | WARP_RELATIVE_MAP, borderType));
  442. }
  443. cv::Mat dstAbsolute;
  444. OCL_ON(uDstAbsolute.copyTo(dstAbsolute));
  445. cv::Mat dstRelative;
  446. OCL_ON(uDstRelative.copyTo(dstRelative));
  447. EXPECT_MAT_NEAR(dstAbsolute, dstRelative, dstAbsolute.depth() == CV_32F ? 1e-3 : 1.0);
  448. }
  449. /////////////////////////////////////////////////////////////////////////////////////
  450. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine, Combine(
  451. Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
  452. Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
  453. Bool(),
  454. Bool()));
  455. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine_cols4, Combine(
  456. Values((MatType)CV_8UC1),
  457. Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
  458. Bool(),
  459. Bool()));
  460. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective, Combine(
  461. Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
  462. Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
  463. Bool(),
  464. Bool()));
  465. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective_cols4, Combine(
  466. Values((MatType)CV_8UC1),
  467. Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
  468. Bool(),
  469. Bool()));
  470. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Resize, Combine(
  471. Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, CV_32FC4),
  472. Values(0.5, 1.5, 2.0, 0.2),
  473. Values(0.5, 1.5, 2.0, 0.2),
  474. Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR),
  475. Bool(),
  476. Values(1, 16)));
  477. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpLinearExact, Resize, Combine(
  478. Values(CV_8UC1, CV_8UC4, CV_16UC2),
  479. Values(0.5, 1.5, 2.0, 0.2),
  480. Values(0.5, 1.5, 2.0, 0.2),
  481. Values((Interpolation)INTER_LINEAR_EXACT),
  482. Bool(),
  483. Values(1, 16)));
  484. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpResizeArea, Resize, Combine(
  485. Values((MatType)CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
  486. Values(0.7, 0.4, 0.5),
  487. Values(0.3, 0.6, 0.5),
  488. Values((Interpolation)INTER_AREA),
  489. Bool(),
  490. Values(1, 16)));
  491. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_LINEAR, Combine(
  492. Values(CV_8U, CV_16U, CV_32F),
  493. Values(1, 3, 4),
  494. Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
  495. std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
  496. std::pair<MatType, MatType>((MatType)CV_32FC2, noType)),
  497. Values((BorderType)BORDER_CONSTANT,
  498. (BorderType)BORDER_REPLICATE,
  499. (BorderType)BORDER_WRAP,
  500. (BorderType)BORDER_REFLECT,
  501. (BorderType)BORDER_REFLECT_101),
  502. Bool()));
  503. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_NEAREST, Combine(
  504. Values(CV_8U, CV_16U, CV_32F),
  505. Values(1, 3, 4),
  506. Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
  507. std::pair<MatType, MatType>((MatType)CV_32FC2, noType),
  508. std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
  509. std::pair<MatType, MatType>((MatType)CV_16SC2, noType)),
  510. Values((BorderType)BORDER_CONSTANT,
  511. (BorderType)BORDER_REPLICATE,
  512. (BorderType)BORDER_WRAP,
  513. (BorderType)BORDER_REFLECT,
  514. (BorderType)BORDER_REFLECT_101),
  515. Bool()));
  516. OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, RemapRelative, Combine(
  517. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  518. Values(1, 3, 4),
  519. Values((Interpolation)INTER_NEAREST,
  520. (Interpolation)INTER_LINEAR,
  521. (Interpolation)INTER_CUBIC,
  522. (Interpolation)INTER_LANCZOS4),
  523. Values((BorderType)BORDER_CONSTANT,
  524. (BorderType)BORDER_REPLICATE,
  525. (BorderType)BORDER_WRAP,
  526. (BorderType)BORDER_REFLECT,
  527. (BorderType)BORDER_REFLECT_101),
  528. Bool()));
  529. } } // namespace opencv_test::ocl
  530. #endif // HAVE_OPENCL