ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
utils_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/utils"
33 #include "util/testing.h"
34 
35 #include "base/essential_matrix.h"
36 #include "estimators/utils.h"
37 
38 using namespace colmap;
39 
40 BOOST_AUTO_TEST_CASE(TestCenterAndNormalizeImagePoints) {
41  std::vector<Eigen::Vector2d> points;
42  for (size_t i = 0; i < 11; ++i) {
43  points.emplace_back(i, i);
44  }
45 
46  std::vector<Eigen::Vector2d> normed_points;
47  Eigen::Matrix3d matrix;
48  CenterAndNormalizeImagePoints(points, &normed_points, &matrix);
49 
50  BOOST_CHECK_EQUAL(matrix(0, 0), 0.31622776601683794);
51  BOOST_CHECK_EQUAL(matrix(1, 1), 0.31622776601683794);
52  BOOST_CHECK_EQUAL(matrix(0, 2), -1.5811388300841898);
53  BOOST_CHECK_EQUAL(matrix(1, 2), -1.5811388300841898);
54 
55  Eigen::Vector2d mean_point(0, 0);
56  for (const auto& point : normed_points) {
57  mean_point += point;
58  }
59  BOOST_CHECK_LT(std::abs(mean_point[0]), 1e-6);
60  BOOST_CHECK_LT(std::abs(mean_point[1]), 1e-6);
61 }
62 
63 BOOST_AUTO_TEST_CASE(TestComputeSquaredSampsonError) {
64  std::vector<Eigen::Vector2d> points1;
65  points1.emplace_back(0, 0);
66  points1.emplace_back(0, 0);
67  points1.emplace_back(0, 0);
68  std::vector<Eigen::Vector2d> points2;
69  points2.emplace_back(2, 0);
70  points2.emplace_back(2, 1);
71  points2.emplace_back(2, 2);
72 
73  const Eigen::Matrix3d E = EssentialMatrixFromPose(Eigen::Matrix3d::Identity(),
74  Eigen::Vector3d(1, 0, 0));
75 
76  std::vector<double> residuals;
77  ComputeSquaredSampsonError(points1, points2, E, &residuals);
78 
79  BOOST_CHECK_EQUAL(residuals.size(), 3);
80  BOOST_CHECK_EQUAL(residuals[0], 0);
81  BOOST_CHECK_EQUAL(residuals[1], 0.5);
82  BOOST_CHECK_EQUAL(residuals[2], 2);
83 }
int points
const double * e
BOOST_AUTO_TEST_CASE(TestCenterAndNormalizeImagePoints)
Definition: utils_test.cc:40
void CenterAndNormalizeImagePoints(const std::vector< Eigen::Vector2d > &points, std::vector< Eigen::Vector2d > *normed_points, Eigen::Matrix3d *matrix)
Definition: utils.cc:38
Eigen::Matrix3d EssentialMatrixFromPose(const Eigen::Matrix3d &R, const Eigen::Vector3d &t)
void ComputeSquaredSampsonError(const std::vector< Eigen::Vector2d > &points1, const std::vector< Eigen::Vector2d > &points2, const Eigen::Matrix3d &E, std::vector< double > *residuals)
Definition: utils.cc:87