ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
fundamental_matrix_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 // its contributors may be used to endorse or promote products derived
16 // from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
31 
32 #define TEST_NAME "estimators/fundamental_matrix"
33 #include "util/testing.h"
34 
36 
37 using namespace colmap;
38 
39 BOOST_AUTO_TEST_CASE(TestSevenPoint) {
40  const double points1_raw[] = {0.4964, 1.0577, 0.3650, -0.0919, -0.5412,
41  0.0159, -0.5239, 0.9467, 0.3467, 0.5301,
42  0.2797, 0.0012, -0.1986, 0.0460};
43 
44  const double points2_raw[] = {0.7570, 2.7340, 0.3961, 0.6981, -0.6014,
45  0.7110, -0.7385, 2.2712, 0.4177, 1.2132,
46  0.3052, 0.4835, -0.2171, 0.5057};
47 
48  const size_t kNumPoints = 7;
49 
50  std::vector<Eigen::Vector2d> points1(kNumPoints);
51  std::vector<Eigen::Vector2d> points2(kNumPoints);
52  for (size_t i = 0; i < kNumPoints; ++i) {
53  points1[i] = Eigen::Vector2d(points1_raw[2 * i], points1_raw[2 * i + 1]);
54  points2[i] = Eigen::Vector2d(points2_raw[2 * i], points2_raw[2 * i + 1]);
55  }
56 
58  const auto F = estimator.Estimate(points1, points2)[0];
59 
60  // Reference values obtained from Matlab.
61  BOOST_CHECK_CLOSE(F(0, 0), 4.81441976, 1e-6);
62  BOOST_CHECK_CLOSE(F(0, 1), -8.16978909, 1e-6);
63  BOOST_CHECK_CLOSE(F(0, 2), 6.73133404, 1e-6);
64  BOOST_CHECK_CLOSE(F(1, 0), 5.16247992, 1e-6);
65  BOOST_CHECK_CLOSE(F(1, 1), 0.19325606, 1e-6);
66  BOOST_CHECK_CLOSE(F(1, 2), -2.87239381, 1e-6);
67  BOOST_CHECK_CLOSE(F(2, 0), -9.92570126, 1e-6);
68  BOOST_CHECK_CLOSE(F(2, 1), 3.64159554, 1e-6);
69  BOOST_CHECK_CLOSE(F(2, 2), 1., 1e-6);
70 }
71 
72 BOOST_AUTO_TEST_CASE(TestEightPoint) {
73  const double points1_raw[] = {1.839035, 1.924743, 0.543582, 0.375221,
74  0.473240, 0.142522, 0.964910, 0.598376,
75  0.102388, 0.140092, 15.994343, 9.622164,
76  0.285901, 0.430055, 0.091150, 0.254594};
77 
78  const double points2_raw[] = {
79  1.002114, 1.129644, 1.521742, 1.846002, 1.084332, 0.275134,
80  0.293328, 0.588992, 0.839509, 0.087290, 1.779735, 1.116857,
81  0.878616, 0.602447, 0.642616, 1.028681,
82  };
83 
84  const size_t kNumPoints = 8;
85  std::vector<Eigen::Vector2d> points1(kNumPoints);
86  std::vector<Eigen::Vector2d> points2(kNumPoints);
87  for (size_t i = 0; i < kNumPoints; ++i) {
88  points1[i] = Eigen::Vector2d(points1_raw[2 * i], points1_raw[2 * i + 1]);
89  points2[i] = Eigen::Vector2d(points2_raw[2 * i], points2_raw[2 * i + 1]);
90  }
91 
93  const auto F = estimator.Estimate(points1, points2)[0];
94 
95  // Reference values obtained from Matlab.
96  BOOST_CHECK(std::abs(F(0, 0) - -0.217859) < 1e-5);
97  BOOST_CHECK(std::abs(F(0, 1) - 0.419282) < 1e-5);
98  BOOST_CHECK(std::abs(F(0, 2) - -0.0343075) < 1e-5);
99  BOOST_CHECK(std::abs(F(1, 0) - -0.0717941) < 1e-5);
100  BOOST_CHECK(std::abs(F(1, 1) - 0.0451643) < 1e-5);
101  BOOST_CHECK(std::abs(F(1, 2) - 0.0216073) < 1e-5);
102  BOOST_CHECK(std::abs(F(2, 0) - 0.248062) < 1e-5);
103  BOOST_CHECK(std::abs(F(2, 1) - -0.429478) < 1e-5);
104  BOOST_CHECK(std::abs(F(2, 2) - 0.0221019) < 1e-5);
105 }
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
const double * e
BOOST_AUTO_TEST_CASE(TestSevenPoint)