test_warpers.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "../test_precomp.hpp"
  42. #include "opencv2/ts/ocl_test.hpp"
  43. #include "opencv2/stitching/warpers.hpp"
  44. #ifdef HAVE_OPENCL
  45. namespace opencv_test {
  46. namespace ocl {
  47. struct WarperTestBase :
  48. public Test, public TestUtils
  49. {
  50. Mat src, dst, xmap, ymap;
  51. UMat usrc, udst, uxmap, uymap;
  52. Mat K, R;
  53. void generateTestData()
  54. {
  55. Size size = randomSize(1, MAX_VALUE);
  56. src = randomMat(size, CV_32FC1, -500, 500);
  57. src.copyTo(usrc);
  58. K = Mat::eye(3, 3, CV_32FC1);
  59. float angle = (float)(30.0 * CV_PI / 180.0);
  60. float rotationMatrix[9] = {
  61. (float)cos(angle), (float)sin(angle), 0,
  62. (float)-sin(angle), (float)cos(angle), 0,
  63. 0, 0, 1
  64. };
  65. Mat(3, 3, CV_32FC1, rotationMatrix).copyTo(R);
  66. }
  67. void Near(double threshold = 0.)
  68. {
  69. EXPECT_MAT_NEAR(xmap, uxmap, threshold);
  70. EXPECT_MAT_NEAR(ymap, uymap, threshold);
  71. EXPECT_MAT_NEAR(dst, udst, threshold);
  72. }
  73. };
  74. typedef WarperTestBase SphericalWarperTest;
  75. OCL_TEST_F(SphericalWarperTest, Mat)
  76. {
  77. for (int j = 0; j < test_loop_times; j++)
  78. {
  79. generateTestData();
  80. Ptr<WarperCreator> creator = makePtr<SphericalWarper>();
  81. Ptr<detail::RotationWarper> warper = creator->create(2.0);
  82. OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
  83. OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
  84. OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
  85. OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
  86. Near(1e-4);
  87. }
  88. }
  89. typedef WarperTestBase CylindricalWarperTest;
  90. OCL_TEST_F(CylindricalWarperTest, Mat)
  91. {
  92. for (int j = 0; j < test_loop_times; j++)
  93. {
  94. generateTestData();
  95. Ptr<WarperCreator> creator = makePtr<CylindricalWarper>();
  96. Ptr<detail::RotationWarper> warper = creator->create(2.0);
  97. OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
  98. OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
  99. OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
  100. OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
  101. Near(1e-4);
  102. }
  103. }
  104. typedef WarperTestBase PlaneWarperTest;
  105. OCL_TEST_F(PlaneWarperTest, Mat)
  106. {
  107. for (int j = 0; j < test_loop_times; j++)
  108. {
  109. generateTestData();
  110. Ptr<WarperCreator> creator = makePtr<PlaneWarper>();
  111. Ptr<detail::RotationWarper> warper = creator->create(2.0);
  112. OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
  113. OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
  114. OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
  115. OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
  116. Near(1.5e-4);
  117. }
  118. }
  119. typedef WarperTestBase AffineWarperTest;
  120. OCL_TEST_F(AffineWarperTest, Mat)
  121. {
  122. for (int j = 0; j < test_loop_times; j++)
  123. {
  124. generateTestData();
  125. Ptr<WarperCreator> creator = makePtr<AffineWarper>();
  126. Ptr<detail::RotationWarper> warper = creator->create(1.0);
  127. OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
  128. OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
  129. OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
  130. OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
  131. Near(1.5e-4);
  132. }
  133. }
  134. } } // namespace opencv_test::ocl
  135. #endif // HAVE_OPENCL