perf_warpers.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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-2013, Advanced Micro Devices, Inc., all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the OpenCV Foundation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #include "../perf_precomp.hpp"
  42. #include "opencv2/stitching/warpers.hpp"
  43. #include "opencv2/ts/ocl_perf.hpp"
  44. #ifdef HAVE_OPENCL
  45. namespace opencv_test {
  46. namespace ocl {
  47. ///////////////////////// Stitching Warpers ///////////////////////////
  48. enum
  49. {
  50. SphericalWarperType = 0,
  51. CylindricalWarperType = 1,
  52. PlaneWarperType = 2,
  53. AffineWarperType = 3,
  54. };
  55. class WarperBase
  56. {
  57. public:
  58. explicit WarperBase(int type, Size srcSize)
  59. {
  60. Ptr<WarperCreator> creator;
  61. if (type == SphericalWarperType)
  62. creator = makePtr<SphericalWarper>();
  63. else if (type == CylindricalWarperType)
  64. creator = makePtr<CylindricalWarper>();
  65. else if (type == PlaneWarperType)
  66. creator = makePtr<PlaneWarper>();
  67. else if (type == AffineWarperType)
  68. creator = makePtr<AffineWarper>();
  69. CV_Assert(!creator.empty());
  70. K = Mat::eye(3, 3, CV_32FC1);
  71. K.at<float>(0,0) = (float)srcSize.width;
  72. K.at<float>(0,2) = (float)srcSize.width/2;
  73. K.at<float>(1,1) = (float)srcSize.height;
  74. K.at<float>(1,2) = (float)srcSize.height/2;
  75. K.at<float>(2,2) = 1.0f;
  76. R = Mat::eye(3, 3, CV_32FC1);
  77. float scale = (float)srcSize.width;
  78. warper = creator->create(scale);
  79. }
  80. Rect buildMaps(Size src_size, OutputArray xmap, OutputArray ymap) const
  81. {
  82. return warper->buildMaps(src_size, K, R, xmap, ymap);
  83. }
  84. Point warp(InputArray src, int interp_mode, int border_mode, OutputArray dst) const
  85. {
  86. return warper->warp(src, K, R, interp_mode, border_mode, dst);
  87. }
  88. private:
  89. Ptr<detail::RotationWarper> warper;
  90. Mat K, R;
  91. };
  92. CV_ENUM(WarperType, SphericalWarperType, CylindricalWarperType, PlaneWarperType, AffineWarperType)
  93. typedef tuple<Size, WarperType> StitchingWarpersParams;
  94. typedef TestBaseWithParam<StitchingWarpersParams> StitchingWarpersFixture;
  95. static void prepareWarperSrc(InputOutputArray src, Size srcSize)
  96. {
  97. src.create(srcSize, CV_8UC1);
  98. src.setTo(Scalar::all(64));
  99. ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/2, srcSize.height/2),
  100. 360, 0, 360, Scalar::all(255), 2);
  101. ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/3, srcSize.height/3),
  102. 360, 0, 360, Scalar::all(128), 2);
  103. rectangle(src, Point(10, 10), Point(srcSize.width - 10, srcSize.height - 10), Scalar::all(128), 2);
  104. }
  105. OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_BuildMaps,
  106. ::testing::Combine(OCL_TEST_SIZES, WarperType::all()))
  107. {
  108. const StitchingWarpersParams params = GetParam();
  109. const Size srcSize = get<0>(params);
  110. const WarperBase warper(get<1>(params), srcSize);
  111. UMat xmap, ymap;
  112. OCL_TEST_CYCLE() warper.buildMaps(srcSize, xmap, ymap);
  113. SANITY_CHECK(xmap, 1e-3);
  114. SANITY_CHECK(ymap, 1e-3);
  115. }
  116. OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_Warp,
  117. ::testing::Combine(OCL_TEST_SIZES, WarperType::all()))
  118. {
  119. const StitchingWarpersParams params = GetParam();
  120. const Size srcSize = get<0>(params);
  121. const WarperBase warper(get<1>(params), srcSize);
  122. UMat src, dst;
  123. prepareWarperSrc(src, srcSize);
  124. declare.in(src, WARMUP_READ);
  125. OCL_TEST_CYCLE() warper.warp(src, INTER_LINEAR, BORDER_REPLICATE, dst);
  126. #if 0
  127. namedWindow("src", WINDOW_NORMAL);
  128. namedWindow("dst", WINDOW_NORMAL);
  129. imshow("src", src);
  130. imshow("dst", dst);
  131. std::cout << dst.size() << " " << dst.size().area() << std::endl;
  132. cv::waitKey();
  133. #endif
  134. SANITY_CHECK(dst, 1e-5);
  135. }
  136. } } // namespace opencv_test::ocl
  137. #endif // HAVE_OPENCL