ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
fundamental_matrix.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <vector>
12 
14 #include "util/alignment.h"
15 #include "util/types.h"
16 
17 namespace colmap {
18 
19 // Fundamental matrix estimator from corresponding point pairs.
20 //
21 // This algorithm solves the 7-Point problem and is based on the following
22 // paper:
23 //
24 // Zhengyou Zhang and T. Kanade, Determining the Epipolar Geometry and its
25 // Uncertainty: A Review, International Journal of Computer Vision, 1998.
26 // http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.33.4540
28 public:
29  typedef Eigen::Vector2d X_t;
30  typedef Eigen::Vector2d Y_t;
31  typedef Eigen::Matrix3d M_t;
32 
33  // The minimum number of samples needed to estimate a model.
34  static const int kMinNumSamples = 7;
35 
36  // Estimate either 1 or 3 possible fundamental matrix solutions from a set
37  // of corresponding points.
38  //
39  // The number of corresponding points must be exactly 7.
40  //
41  // @param points1 First set of corresponding points.
42  // @param points2 Second set of corresponding points
43  //
44  // @return Up to 4 solutions as a vector of 3x3 fundamental
45  // matrices.
46  static std::vector<M_t> Estimate(const std::vector<X_t>& points1,
47  const std::vector<Y_t>& points2);
48 
49  // Calculate the residuals of a set of corresponding points and a given
50  // fundamental matrix.
51  //
52  // Residuals are defined as the squared Sampson error.
53  //
54  // @param points1 First set of corresponding points as Nx2 matrix.
55  // @param points2 Second set of corresponding points as Nx2 matrix.
56  // @param F 3x3 fundamental matrix.
57  // @param residuals Output vector of residuals.
58  static void Residuals(const std::vector<X_t>& points1,
59  const std::vector<Y_t>& points2,
60  const M_t& F,
61  std::vector<double>* residuals);
62 };
63 
64 // Fundamental matrix estimator from corresponding point pairs.
65 //
66 // This algorithm solves the 8-Point problem based on the following paper:
67 //
68 // Hartley and Zisserman, Multiple View Geometry, algorithm 11.1, page 282.
70 public:
71  typedef Eigen::Vector2d X_t;
72  typedef Eigen::Vector2d Y_t;
73  typedef Eigen::Matrix3d M_t;
74 
75  // The minimum number of samples needed to estimate a model.
76  static const int kMinNumSamples = 8;
77 
78  // Estimate fundamental matrix solutions from a set of corresponding points.
79  //
80  // The number of corresponding points must be at least 8.
81  //
82  // @param points1 First set of corresponding points.
83  // @param points2 Second set of corresponding points
84  //
85  // @return Single solution as a vector of 3x3 fundamental matrices.
86  static std::vector<M_t> Estimate(const std::vector<X_t>& points1,
87  const std::vector<Y_t>& points2);
88 
89  // Calculate the residuals of a set of corresponding points and a given
90  // fundamental matrix.
91  //
92  // Residuals are defined as the squared Sampson error.
93  //
94  // @param points1 First set of corresponding points as Nx2 matrix.
95  // @param points2 Second set of corresponding points as Nx2 matrix.
96  // @param F 3x3 fundamental matrix.
97  // @param residuals Output vector of residuals.
98  static void Residuals(const std::vector<X_t>& points1,
99  const std::vector<Y_t>& points2,
100  const M_t& F,
101  std::vector<double>* residuals);
102 };
103 
104 } // namespace colmap
types.h
colmap::FundamentalMatrixSevenPointEstimator::M_t
Eigen::Matrix3d M_t
Definition: fundamental_matrix.h:31
colmap::FundamentalMatrixEightPointEstimator::Estimate
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
Definition: fundamental_matrix.cc:152
colmap::FundamentalMatrixEightPointEstimator::M_t
Eigen::Matrix3d M_t
Definition: fundamental_matrix.h:73
x
normal_z x
Definition: my_point_types.h:165
colmap::FundamentalMatrixSevenPointEstimator::kMinNumSamples
static const int kMinNumSamples
Definition: fundamental_matrix.h:34
polynomial.h
alignment.h
colmap::FundamentalMatrixSevenPointEstimator::X_t
Eigen::Vector2d X_t
Definition: fundamental_matrix.h:29
colmap::CenterAndNormalizeImagePoints
void CenterAndNormalizeImagePoints(const std::vector< Eigen::Vector2d > &points, std::vector< Eigen::Vector2d > *normed_points, Eigen::Matrix3d *matrix)
Definition: utils.cc:38
colmap::FundamentalMatrixSevenPointEstimator::Estimate
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
Definition: fundamental_matrix.cc:49
colmap::FindPolynomialRootsCompanionMatrix
bool FindPolynomialRootsCompanionMatrix(const Eigen::VectorXd &coeffs_all, Eigen::VectorXd *real, Eigen::VectorXd *imag)
Definition: polynomial.cc:208
y
normal_z y
Definition: my_point_types.h:168
colmap::FundamentalMatrixEightPointEstimator
Definition: fundamental_matrix.h:69
colmap::FundamentalMatrixSevenPointEstimator::Residuals
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &F, std::vector< double > *residuals)
Definition: fundamental_matrix.cc:145
e
const double * e
Definition: essential_matrix_poly.h:10
colmap::FundamentalMatrixEightPointEstimator::kMinNumSamples
static const int kMinNumSamples
Definition: fundamental_matrix.h:76
knncpp::Index
Eigen::MatrixXd::Index Index
Definition: knncpp.h:26
coeffs
coeffs(0)
colmap::ComputeSquaredSampsonError
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
homography_matrix.h
colmap::FundamentalMatrixEightPointEstimator::Residuals
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &F, std::vector< double > *residuals)
Definition: fundamental_matrix.cc:195
colmap::FundamentalMatrixSevenPointEstimator
Definition: fundamental_matrix.h:27
fundamental_matrix.h
colmap::FundamentalMatrixEightPointEstimator::X_t
Eigen::Vector2d X_t
Definition: fundamental_matrix.h:71
logging.h
colmap
Definition: AutomaticReconstructionController.h:17
colmap::FundamentalMatrixEightPointEstimator::Y_t
Eigen::Vector2d Y_t
Definition: fundamental_matrix.h:72
utils.h
colmap::FundamentalMatrixSevenPointEstimator::Y_t
Eigen::Vector2d Y_t
Definition: fundamental_matrix.h:30