test_reprojection.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. #include "opencv2/stitching/warpers.hpp"
  6. namespace opencv_test { namespace {
  7. class ReprojectionTest : public ::testing::Test {
  8. protected:
  9. const size_t TEST_COUNT = 15;
  10. Mat K, R;
  11. RNG rng = RNG(0);
  12. ReprojectionTest()
  13. {
  14. K = Mat::eye(3, 3, CV_32FC1);
  15. float angle = (float)(30.0 * CV_PI / 180.0);
  16. float rotationMatrix[9] = {
  17. (float)cos(angle), (float)sin(angle), 0,
  18. (float)-sin(angle), (float)cos(angle), 0,
  19. 0, 0, 1
  20. };
  21. Mat(3, 3, CV_32FC1, rotationMatrix).copyTo(R);
  22. }
  23. void TestReprojection(Ptr<detail::RotationWarper> warper, Point2f pt) {
  24. Point2f projected_pt = warper->warpPoint(pt, K, R);
  25. Point2f reprojected_pt = warper->warpPointBackward(projected_pt, K, R);
  26. EXPECT_NEAR(pt.x, reprojected_pt.x, float( 1e-5));
  27. EXPECT_NEAR(pt.y, reprojected_pt.y, float( 1e-5));
  28. }
  29. };
  30. TEST_F(ReprojectionTest, PlaneWarper)
  31. {
  32. Ptr<WarperCreator> creator = makePtr<PlaneWarper>();
  33. for (size_t i = 0; i < TEST_COUNT; ++i) {
  34. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  35. }
  36. }
  37. TEST_F(ReprojectionTest, AffineWarper)
  38. {
  39. Ptr<WarperCreator> creator = makePtr<AffineWarper>();
  40. for (size_t i = 0; i < TEST_COUNT; ++i) {
  41. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  42. }
  43. }
  44. TEST_F(ReprojectionTest, CylindricalWarper)
  45. {
  46. Ptr<WarperCreator> creator = makePtr<CylindricalWarper>();
  47. for (size_t i = 0; i < TEST_COUNT; ++i) {
  48. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  49. }
  50. }
  51. TEST_F(ReprojectionTest, SphericalWarper)
  52. {
  53. Ptr<WarperCreator> creator = makePtr<SphericalWarper>();
  54. for (size_t i = 0; i < TEST_COUNT; ++i) {
  55. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  56. }
  57. }
  58. TEST_F(ReprojectionTest, FisheyeWarper)
  59. {
  60. Ptr<WarperCreator> creator = makePtr<FisheyeWarper>();
  61. for (size_t i = 0; i < TEST_COUNT; ++i) {
  62. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  63. }
  64. }
  65. TEST_F(ReprojectionTest, StereographicWarper)
  66. {
  67. Ptr<WarperCreator> creator = makePtr<StereographicWarper>();
  68. for (size_t i = 0; i < TEST_COUNT; ++i) {
  69. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  70. }
  71. }
  72. TEST_F(ReprojectionTest, CompressedRectilinearWarper)
  73. {
  74. Ptr<WarperCreator> creator = makePtr<CompressedRectilinearWarper>(1.5f, 1.0f);
  75. for (size_t i = 0; i < TEST_COUNT; ++i) {
  76. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  77. }
  78. }
  79. TEST_F(ReprojectionTest, CompressedRectilinearPortraitWarper)
  80. {
  81. Ptr<WarperCreator> creator = makePtr<CompressedRectilinearPortraitWarper>(1.5f, 1.0f);
  82. for (size_t i = 0; i < TEST_COUNT; ++i) {
  83. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  84. }
  85. }
  86. TEST_F(ReprojectionTest, PaniniWarper)
  87. {
  88. Ptr<WarperCreator> creator = makePtr<PaniniWarper>(1.5f, 1.0f);
  89. for (size_t i = 0; i < TEST_COUNT; ++i) {
  90. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  91. }
  92. }
  93. TEST_F(ReprojectionTest, PaniniPortraitWarper)
  94. {
  95. Ptr<WarperCreator> creator = makePtr<PaniniPortraitWarper>(1.5f, 1.0f);
  96. for (size_t i = 0; i < TEST_COUNT; ++i) {
  97. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  98. }
  99. }
  100. TEST_F(ReprojectionTest, MercatorWarper)
  101. {
  102. Ptr<WarperCreator> creator = makePtr<MercatorWarper>();
  103. for (size_t i = 0; i < TEST_COUNT; ++i) {
  104. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  105. }
  106. }
  107. TEST_F(ReprojectionTest, TransverseMercatorWarper)
  108. {
  109. Ptr<WarperCreator> creator = makePtr<TransverseMercatorWarper>();
  110. for (size_t i = 0; i < TEST_COUNT; ++i) {
  111. TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
  112. }
  113. }
  114. }} // namespace