ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
essential_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 <ceres/ceres.h>
11 
12 #include <Eigen/Core>
13 #include <vector>
14 
15 #include "util/alignment.h"
16 #include "util/types.h"
17 
18 namespace colmap {
19 
20 // Essential matrix estimator from corresponding normalized point pairs.
21 //
22 // This algorithm solves the 5-Point problem based on the following paper:
23 //
24 // D. Nister, An efficient solution to the five-point relative pose problem,
25 // IEEE-T-PAMI, 26(6), 2004.
26 // http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.86.8769
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 = 5;
35 
36  // Estimate up to 10 possible essential matrix solutions from a set of
37  // corresponding points.
38  //
39  // The number of corresponding points must be at least 5.
40  //
41  // @param points1 First set of corresponding points.
42  // @param points2 Second set of corresponding points.
43  //
44  // @return Up to 10 solutions as a vector of 3x3 essential matrices.
45  static std::vector<M_t> Estimate(const std::vector<X_t>& points1,
46  const std::vector<Y_t>& points2);
47 
48  // Calculate the residuals of a set of corresponding points and a given
49  // essential matrix.
50  //
51  // Residuals are defined as the squared Sampson error.
52  //
53  // @param points1 First set of corresponding points.
54  // @param points2 Second set of corresponding points.
55  // @param E 3x3 essential matrix.
56  // @param residuals Output vector of residuals.
57  static void Residuals(const std::vector<X_t>& points1,
58  const std::vector<Y_t>& points2,
59  const M_t& E,
60  std::vector<double>* residuals);
61 };
62 
63 // Essential matrix estimator from corresponding normalized point pairs.
64 //
65 // This algorithm solves the 8-Point problem based on the following paper:
66 //
67 // Hartley and Zisserman, Multiple View Geometry, algorithm 11.1, page 282.
69 public:
70  typedef Eigen::Vector2d X_t;
71  typedef Eigen::Vector2d Y_t;
72  typedef Eigen::Matrix3d M_t;
73 
74  // The minimum number of samples needed to estimate a model.
75  static const int kMinNumSamples = 8;
76 
77  // Estimate essential matrix solutions from set of corresponding points.
78  //
79  // The number of corresponding points must be at least 8.
80  //
81  // @param points1 First set of corresponding points.
82  // @param points2 Second set of corresponding points.
83  static std::vector<M_t> Estimate(const std::vector<X_t>& points1,
84  const std::vector<Y_t>& points2);
85 
86  // Calculate the residuals of a set of corresponding points and a given
87  // essential matrix.
88  //
89  // Residuals are defined as the squared Sampson error.
90  //
91  // @param points1 First set of corresponding points.
92  // @param points2 Second set of corresponding points.
93  // @param E 3x3 essential matrix.
94  // @param residuals Output vector of residuals.
95  static void Residuals(const std::vector<X_t>& points1,
96  const std::vector<Y_t>& points2,
97  const M_t& E,
98  std::vector<double>* residuals);
99 };
100 
101 } // namespace colmap
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &E, 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 &E, std::vector< double > *residuals)
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)