perf_imgwarp.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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, Multicoreware, Inc., all rights reserved.
  14. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // @Authors
  18. // Fangfang Bai, fangfang@multicorewareinc.com
  19. // Jin Ma, jin@multicorewareinc.com
  20. //
  21. // Redistribution and use in source and binary forms, with or without modification,
  22. // are permitted provided that the following conditions are met:
  23. //
  24. // * Redistribution's of source code must retain the above copyright notice,
  25. // this list of conditions and the following disclaimer.
  26. //
  27. // * Redistribution's in binary form must reproduce the above copyright notice,
  28. // this list of conditions and the following disclaimer in the documentation
  29. // and/or other materials provided with the distribution.
  30. //
  31. // * The name of the copyright holders may not be used to endorse or promote products
  32. // derived from this software without specific prior written permission.
  33. //
  34. // This software is provided by the copyright holders and contributors as is and
  35. // any express or implied warranties, including, but not limited to, the implied
  36. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  37. // In no event shall the Intel Corporation or contributors be liable for any direct,
  38. // indirect, incidental, special, exemplary, or consequential damages
  39. // (including, but not limited to, procurement of substitute goods or services;
  40. // loss of use, data, or profits; or business interruption) however caused
  41. // and on any theory of liability, whether in contract, strict liability,
  42. // or tort (including negligence or otherwise) arising in any way out of
  43. // the use of this software, even if advised of the possibility of such damage.
  44. //
  45. //M*/
  46. #include "../perf_precomp.hpp"
  47. #include "opencv2/ts/ocl_perf.hpp"
  48. #ifdef HAVE_OPENCL
  49. namespace opencv_test {
  50. namespace ocl {
  51. ///////////// WarpAffine ////////////////////////
  52. CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
  53. typedef tuple<Size, MatType, InterType> WarpAffineParams;
  54. typedef TestBaseWithParam<WarpAffineParams> WarpAffineFixture;
  55. OCL_PERF_TEST_P(WarpAffineFixture, WarpAffine,
  56. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, InterType::all()))
  57. {
  58. static const double coeffs[2][3] =
  59. {
  60. { cos(CV_PI / 6), -sin(CV_PI / 6), 100.0 },
  61. { sin(CV_PI / 6), cos(CV_PI / 6) , -100.0 }
  62. };
  63. Mat M(2, 3, CV_64F, (void *)coeffs);
  64. const WarpAffineParams params = GetParam();
  65. const Size srcSize = get<0>(params);
  66. const int type = get<1>(params), interpolation = get<2>(params);
  67. const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : interpolation == INTER_CUBIC ? 2e-3 : 1e-4;
  68. checkDeviceMaxMemoryAllocSize(srcSize, type);
  69. UMat src(srcSize, type), dst(srcSize, type);
  70. declare.in(src, WARMUP_RNG).out(dst);
  71. OCL_TEST_CYCLE() cv::warpAffine(src, dst, M, srcSize, interpolation);
  72. SANITY_CHECK(dst, eps);
  73. }
  74. ///////////// WarpPerspective ////////////////////////
  75. typedef WarpAffineParams WarpPerspectiveParams;
  76. typedef TestBaseWithParam<WarpPerspectiveParams> WarpPerspectiveFixture;
  77. OCL_PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective,
  78. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
  79. OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))
  80. {
  81. static const double coeffs[3][3] =
  82. {
  83. {cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},
  84. {sin(CV_PI / 6), cos(CV_PI / 6), -100.0},
  85. {0.0, 0.0, 1.0}
  86. };
  87. Mat M(3, 3, CV_64F, (void *)coeffs);
  88. const WarpPerspectiveParams params = GetParam();
  89. const Size srcSize = get<0>(params);
  90. const int type = get<1>(params), interpolation = get<2>(params);
  91. const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
  92. checkDeviceMaxMemoryAllocSize(srcSize, type);
  93. UMat src(srcSize, type), dst(srcSize, type);
  94. declare.in(src, WARMUP_RNG).out(dst);
  95. OCL_TEST_CYCLE() cv::warpPerspective(src, dst, M, srcSize, interpolation);
  96. SANITY_CHECK(dst, eps);
  97. }
  98. ///////////// Resize ////////////////////////
  99. typedef tuple<Size, MatType, InterType, double> ResizeParams;
  100. typedef TestBaseWithParam<ResizeParams> ResizeFixture;
  101. OCL_PERF_TEST_P(ResizeFixture, Resize,
  102. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
  103. OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR)),
  104. ::testing::Values(0.5, 2.0)))
  105. {
  106. const ResizeParams params = GetParam();
  107. const Size srcSize = get<0>(params);
  108. const int type = get<1>(params), interType = get<2>(params);
  109. double scale = get<3>(params);
  110. const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
  111. const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
  112. checkDeviceMaxMemoryAllocSize(srcSize, type);
  113. checkDeviceMaxMemoryAllocSize(dstSize, type);
  114. UMat src(srcSize, type), dst(dstSize, type);
  115. declare.in(src, WARMUP_RNG).out(dst);
  116. OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, interType);
  117. SANITY_CHECK(dst, eps);
  118. }
  119. typedef tuple<Size, MatType, double> ResizeAreaParams;
  120. typedef TestBaseWithParam<ResizeAreaParams> ResizeAreaFixture;
  121. OCL_PERF_TEST_P(ResizeAreaFixture, Resize,
  122. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, ::testing::Values(0.3, 0.5, 0.6)))
  123. {
  124. const ResizeAreaParams params = GetParam();
  125. const Size srcSize = get<0>(params);
  126. const int type = get<1>(params);
  127. double scale = get<2>(params);
  128. const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
  129. const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
  130. checkDeviceMaxMemoryAllocSize(srcSize, type);
  131. checkDeviceMaxMemoryAllocSize(dstSize, type);
  132. UMat src(srcSize, type), dst(dstSize, type);
  133. declare.in(src, WARMUP_RNG).out(dst);
  134. OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_AREA);
  135. SANITY_CHECK(dst, eps);
  136. }
  137. typedef ResizeAreaParams ResizeLinearExactParams;
  138. typedef TestBaseWithParam<ResizeLinearExactParams> ResizeLinearExactFixture;
  139. OCL_PERF_TEST_P(ResizeLinearExactFixture, Resize,
  140. ::testing::Combine(OCL_TEST_SIZES, ::testing::Values(CV_8UC1, CV_8UC3, CV_8UC4), ::testing::Values(0.5, 2.0)))
  141. {
  142. const ResizeAreaParams params = GetParam();
  143. const Size srcSize = get<0>(params);
  144. const int type = get<1>(params);
  145. double scale = get<2>(params);
  146. const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
  147. const double eps = 1e-4;
  148. checkDeviceMaxMemoryAllocSize(srcSize, type);
  149. checkDeviceMaxMemoryAllocSize(dstSize, type);
  150. UMat src(srcSize, type), dst(dstSize, type);
  151. declare.in(src, WARMUP_RNG).out(dst);
  152. OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_LINEAR_EXACT);
  153. SANITY_CHECK(dst, eps);
  154. }
  155. ///////////// Remap ////////////////////////
  156. typedef tuple<Size, MatType, InterType> RemapParams;
  157. typedef TestBaseWithParam<RemapParams> RemapFixture;
  158. OCL_PERF_TEST_P(RemapFixture, Remap,
  159. ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
  160. OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))
  161. {
  162. const RemapParams params = GetParam();
  163. const Size srcSize = get<0>(params);
  164. const int type = get<1>(params), interpolation = get<2>(params), borderMode = BORDER_CONSTANT;
  165. //const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
  166. checkDeviceMaxMemoryAllocSize(srcSize, type);
  167. UMat src(srcSize, type), dst(srcSize, type);
  168. UMat xmap(srcSize, CV_32FC1), ymap(srcSize, CV_32FC1);
  169. {
  170. Mat _xmap = xmap.getMat(ACCESS_WRITE), _ymap = ymap.getMat(ACCESS_WRITE);
  171. for (int i = 0; i < srcSize.height; ++i)
  172. {
  173. float * const xmap_row = _xmap.ptr<float>(i);
  174. float * const ymap_row = _ymap.ptr<float>(i);
  175. for (int j = 0; j < srcSize.width; ++j)
  176. {
  177. xmap_row[j] = (j - srcSize.width * 0.5f) * 0.75f + srcSize.width * 0.5f;
  178. ymap_row[j] = (i - srcSize.height * 0.5f) * 0.75f + srcSize.height * 0.5f;
  179. }
  180. }
  181. }
  182. declare.in(src, WARMUP_RNG).in(xmap, ymap, WARMUP_READ).out(dst);
  183. OCL_TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
  184. SANITY_CHECK_NOTHING();
  185. }
  186. } } // namespace opencv_test::ocl
  187. #endif // HAVE_OPENCL