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
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &F, std::vector< double > *residuals)
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &F, std::vector< double > *residuals)
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)