perf_warping.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "perf_precomp.hpp"
  43. namespace opencv_test { namespace {
  44. //////////////////////////////////////////////////////////////////////
  45. // Remap
  46. enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH };
  47. CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
  48. void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode)
  49. {
  50. for (int j = 0; j < map_x.rows; ++j)
  51. {
  52. for (int i = 0; i < map_x.cols; ++i)
  53. {
  54. switch (remapMode)
  55. {
  56. case HALF_SIZE:
  57. if (i > map_x.cols*0.25 && i < map_x.cols*0.75 && j > map_x.rows*0.25 && j < map_x.rows*0.75)
  58. {
  59. map_x.at<float>(j,i) = 2.f * (i - map_x.cols * 0.25f) + 0.5f;
  60. map_y.at<float>(j,i) = 2.f * (j - map_x.rows * 0.25f) + 0.5f;
  61. }
  62. else
  63. {
  64. map_x.at<float>(j,i) = 0.f;
  65. map_y.at<float>(j,i) = 0.f;
  66. }
  67. break;
  68. case UPSIDE_DOWN:
  69. map_x.at<float>(j,i) = static_cast<float>(i);
  70. map_y.at<float>(j,i) = static_cast<float>(map_x.rows - j);
  71. break;
  72. case REFLECTION_X:
  73. map_x.at<float>(j,i) = static_cast<float>(map_x.cols - i);
  74. map_y.at<float>(j,i) = static_cast<float>(j);
  75. break;
  76. case REFLECTION_BOTH:
  77. map_x.at<float>(j,i) = static_cast<float>(map_x.cols - i);
  78. map_y.at<float>(j,i) = static_cast<float>(map_x.rows - j);
  79. break;
  80. } // end of switch
  81. }
  82. }
  83. }
  84. DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border_Mode, cv::Size, MatDepth, MatCn, Interpolation, BorderMode, RemapMode);
  85. PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, Remap,
  86. Combine(CUDA_TYPICAL_MAT_SIZES,
  87. Values(CV_8U, CV_16U, CV_32F),
  88. CUDA_CHANNELS_1_3_4,
  89. Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
  90. ALL_BORDER_MODES,
  91. RemapMode::all()))
  92. {
  93. declare.time(20.0);
  94. const cv::Size size = GET_PARAM(0);
  95. const int depth = GET_PARAM(1);
  96. const int channels = GET_PARAM(2);
  97. const int interpolation = GET_PARAM(3);
  98. const int borderMode = GET_PARAM(4);
  99. const int remapMode = GET_PARAM(5);
  100. const int type = CV_MAKE_TYPE(depth, channels);
  101. cv::Mat src(size, type);
  102. declare.in(src, WARMUP_RNG);
  103. cv::Mat xmap(size, CV_32FC1);
  104. cv::Mat ymap(size, CV_32FC1);
  105. generateMap(xmap, ymap, remapMode);
  106. if (PERF_RUN_CUDA())
  107. {
  108. const cv::cuda::GpuMat d_src(src);
  109. const cv::cuda::GpuMat d_xmap(xmap);
  110. const cv::cuda::GpuMat d_ymap(ymap);
  111. cv::cuda::GpuMat dst;
  112. TEST_CYCLE() cv::cuda::remap(d_src, dst, d_xmap, d_ymap, interpolation, borderMode);
  113. CUDA_SANITY_CHECK(dst);
  114. }
  115. else
  116. {
  117. cv::Mat dst;
  118. TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
  119. CPU_SANITY_CHECK(dst);
  120. }
  121. }
  122. //////////////////////////////////////////////////////////////////////
  123. // Resize
  124. DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Scale, cv::Size, MatDepth, MatCn, Interpolation, double);
  125. PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, Resize,
  126. Combine(CUDA_TYPICAL_MAT_SIZES,
  127. Values(CV_8U, CV_16U, CV_32F),
  128. CUDA_CHANNELS_1_3_4,
  129. Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
  130. Values(0.5, 0.3, 2.0)))
  131. {
  132. declare.time(20.0);
  133. const cv::Size size = GET_PARAM(0);
  134. const int depth = GET_PARAM(1);
  135. const int channels = GET_PARAM(2);
  136. const int interpolation = GET_PARAM(3);
  137. const double f = GET_PARAM(4);
  138. const int type = CV_MAKE_TYPE(depth, channels);
  139. cv::Mat src(size, type);
  140. declare.in(src, WARMUP_RNG);
  141. if (PERF_RUN_CUDA())
  142. {
  143. const cv::cuda::GpuMat d_src(src);
  144. cv::cuda::GpuMat dst;
  145. TEST_CYCLE() cv::cuda::resize(d_src, dst, cv::Size(), f, f, interpolation);
  146. CUDA_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
  147. }
  148. else
  149. {
  150. cv::Mat dst;
  151. TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
  152. CPU_SANITY_CHECK(dst);
  153. }
  154. }
  155. //////////////////////////////////////////////////////////////////////
  156. // ResizeArea
  157. DEF_PARAM_TEST(Sz_Depth_Cn_Scale, cv::Size, MatDepth, MatCn, double);
  158. PERF_TEST_P(Sz_Depth_Cn_Scale, ResizeArea,
  159. Combine(CUDA_TYPICAL_MAT_SIZES,
  160. Values(CV_8U, CV_16U, CV_32F),
  161. CUDA_CHANNELS_1_3_4,
  162. Values(0.2, 0.1, 0.05)))
  163. {
  164. declare.time(1.0);
  165. const cv::Size size = GET_PARAM(0);
  166. const int depth = GET_PARAM(1);
  167. const int channels = GET_PARAM(2);
  168. const int interpolation = cv::INTER_AREA;
  169. const double f = GET_PARAM(3);
  170. const int type = CV_MAKE_TYPE(depth, channels);
  171. cv::Mat src(size, type);
  172. declare.in(src, WARMUP_RNG);
  173. if (PERF_RUN_CUDA())
  174. {
  175. const cv::cuda::GpuMat d_src(src);
  176. cv::cuda::GpuMat dst;
  177. TEST_CYCLE() cv::cuda::resize(d_src, dst, cv::Size(), f, f, interpolation);
  178. CUDA_SANITY_CHECK(dst);
  179. }
  180. else
  181. {
  182. cv::Mat dst;
  183. TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
  184. CPU_SANITY_CHECK(dst);
  185. }
  186. }
  187. //////////////////////////////////////////////////////////////////////
  188. // WarpAffine
  189. DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border, cv::Size, MatDepth, MatCn, Interpolation, BorderMode);
  190. PERF_TEST_P(Sz_Depth_Cn_Inter_Border, WarpAffine,
  191. Combine(CUDA_TYPICAL_MAT_SIZES,
  192. Values(CV_8U, CV_16U, CV_32F),
  193. CUDA_CHANNELS_1_3_4,
  194. Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
  195. ALL_BORDER_MODES))
  196. {
  197. declare.time(20.0);
  198. const cv::Size size = GET_PARAM(0);
  199. const int depth = GET_PARAM(1);
  200. const int channels = GET_PARAM(2);
  201. const int interpolation = GET_PARAM(3);
  202. const int borderMode = GET_PARAM(4);
  203. const int type = CV_MAKE_TYPE(depth, channels);
  204. cv::Mat src(size, type);
  205. declare.in(src, WARMUP_RNG);
  206. const double aplha = CV_PI / 4;
  207. const double mat[2 * 3] =
  208. {
  209. std::cos(aplha), -std::sin(aplha), static_cast<double>(src.cols) / 2.0,
  210. std::sin(aplha), std::cos(aplha), 0
  211. };
  212. const cv::Mat M(2, 3, CV_64F, (void*) mat);
  213. if (PERF_RUN_CUDA())
  214. {
  215. const cv::cuda::GpuMat d_src(src);
  216. cv::cuda::GpuMat dst;
  217. TEST_CYCLE() cv::cuda::warpAffine(d_src, dst, M, size, interpolation, borderMode);
  218. CUDA_SANITY_CHECK(dst, 1);
  219. }
  220. else
  221. {
  222. cv::Mat dst;
  223. TEST_CYCLE() cv::warpAffine(src, dst, M, size, interpolation, borderMode);
  224. CPU_SANITY_CHECK(dst);
  225. }
  226. }
  227. //////////////////////////////////////////////////////////////////////
  228. // WarpPerspective
  229. PERF_TEST_P(Sz_Depth_Cn_Inter_Border, WarpPerspective,
  230. Combine(CUDA_TYPICAL_MAT_SIZES,
  231. Values(CV_8U, CV_16U, CV_32F),
  232. CUDA_CHANNELS_1_3_4,
  233. Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
  234. ALL_BORDER_MODES))
  235. {
  236. declare.time(20.0);
  237. const cv::Size size = GET_PARAM(0);
  238. const int depth = GET_PARAM(1);
  239. const int channels = GET_PARAM(2);
  240. const int interpolation = GET_PARAM(3);
  241. const int borderMode = GET_PARAM(4);
  242. const int type = CV_MAKE_TYPE(depth, channels);
  243. cv::Mat src(size, type);
  244. declare.in(src, WARMUP_RNG);
  245. const double aplha = CV_PI / 4;
  246. double mat[3][3] = { {std::cos(aplha), -std::sin(aplha), static_cast<double>(src.cols) / 2.0},
  247. {std::sin(aplha), std::cos(aplha), 0},
  248. {0.0, 0.0, 1.0}};
  249. const cv::Mat M(3, 3, CV_64F, (void*) mat);
  250. if (PERF_RUN_CUDA())
  251. {
  252. const cv::cuda::GpuMat d_src(src);
  253. cv::cuda::GpuMat dst;
  254. TEST_CYCLE() cv::cuda::warpPerspective(d_src, dst, M, size, interpolation, borderMode);
  255. CUDA_SANITY_CHECK(dst, 1);
  256. }
  257. else
  258. {
  259. cv::Mat dst;
  260. TEST_CYCLE() cv::warpPerspective(src, dst, M, size, interpolation, borderMode);
  261. CPU_SANITY_CHECK(dst);
  262. }
  263. }
  264. //////////////////////////////////////////////////////////////////////
  265. // Rotate
  266. DEF_PARAM_TEST(Sz_Depth_Cn_Inter, cv::Size, MatDepth, MatCn, Interpolation);
  267. PERF_TEST_P(Sz_Depth_Cn_Inter, Rotate,
  268. Combine(CUDA_TYPICAL_MAT_SIZES,
  269. Values(CV_8U, CV_16U, CV_32F),
  270. CUDA_CHANNELS_1_3_4,
  271. Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))))
  272. {
  273. const cv::Size size = GET_PARAM(0);
  274. const int depth = GET_PARAM(1);
  275. const int channels = GET_PARAM(2);
  276. const int interpolation = GET_PARAM(3);
  277. const int type = CV_MAKE_TYPE(depth, channels);
  278. cv::Mat src(size, type);
  279. declare.in(src, WARMUP_RNG);
  280. if (PERF_RUN_CUDA())
  281. {
  282. const cv::cuda::GpuMat d_src(src);
  283. cv::cuda::GpuMat dst;
  284. TEST_CYCLE() cv::cuda::rotate(d_src, dst, size, 30.0, 0, 0, interpolation);
  285. CUDA_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
  286. }
  287. else
  288. {
  289. FAIL_NO_CPU();
  290. }
  291. }
  292. //////////////////////////////////////////////////////////////////////
  293. // PyrDown
  294. DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
  295. PERF_TEST_P(Sz_Depth_Cn, PyrDown,
  296. Combine(CUDA_TYPICAL_MAT_SIZES,
  297. Values(CV_8U, CV_16U, CV_32F),
  298. CUDA_CHANNELS_1_3_4))
  299. {
  300. const cv::Size size = GET_PARAM(0);
  301. const int depth = GET_PARAM(1);
  302. const int channels = GET_PARAM(2);
  303. const int type = CV_MAKE_TYPE(depth, channels);
  304. cv::Mat src(size, type);
  305. declare.in(src, WARMUP_RNG);
  306. if (PERF_RUN_CUDA())
  307. {
  308. const cv::cuda::GpuMat d_src(src);
  309. cv::cuda::GpuMat dst;
  310. TEST_CYCLE() cv::cuda::pyrDown(d_src, dst);
  311. CUDA_SANITY_CHECK(dst);
  312. }
  313. else
  314. {
  315. cv::Mat dst;
  316. TEST_CYCLE() cv::pyrDown(src, dst);
  317. CPU_SANITY_CHECK(dst);
  318. }
  319. }
  320. //////////////////////////////////////////////////////////////////////
  321. // PyrUp
  322. PERF_TEST_P(Sz_Depth_Cn, PyrUp,
  323. Combine(CUDA_TYPICAL_MAT_SIZES,
  324. Values(CV_8U, CV_16U, CV_32F),
  325. CUDA_CHANNELS_1_3_4))
  326. {
  327. const cv::Size size = GET_PARAM(0);
  328. const int depth = GET_PARAM(1);
  329. const int channels = GET_PARAM(2);
  330. const int type = CV_MAKE_TYPE(depth, channels);
  331. cv::Mat src(size, type);
  332. declare.in(src, WARMUP_RNG);
  333. if (PERF_RUN_CUDA())
  334. {
  335. const cv::cuda::GpuMat d_src(src);
  336. cv::cuda::GpuMat dst;
  337. TEST_CYCLE() cv::cuda::pyrUp(d_src, dst);
  338. CUDA_SANITY_CHECK(dst);
  339. }
  340. else
  341. {
  342. cv::Mat dst;
  343. TEST_CYCLE() cv::pyrUp(src, dst);
  344. CPU_SANITY_CHECK(dst);
  345. }
  346. }
  347. }} // namespace