ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
generalized_relative_pose.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 
13 #include "util/alignment.h"
14 #include "util/types.h"
15 
16 namespace colmap {
17 
18 // Solver for the Generalized Relative Pose problem using a minimal of 8 2D-2D
19 // correspondences. This implementation is based on:
20 //
21 // "Efficient Computation of Relative Pose for Multi-Camera Systems",
22 // Kneip and Li. CVPR 2014.
23 //
24 // Note that the solution to this problem is degenerate in the case of pure
25 // translation and when all correspondences are observed from the same cameras.
26 //
27 // The implementation is a modified and improved version of Kneip's original
28 // implementation in OpenGV licensed under the BSD license.
30 public:
31  // The generalized image observations of the left camera, which is composed
32  // of the relative pose of the specific camera in the generalized camera and
33  // its image observation.
34  struct X_t {
35  // The relative transformation from the generalized camera to the camera
36  // frame of the observation.
38  // The 2D image feature observation.
39  Eigen::Vector2d xy;
40  };
41 
42  // The normalized image feature points in the left camera.
43  typedef X_t Y_t;
44  // The relative transformation between the two generalized cameras.
46 
47  // The minimum number of samples needed to estimate a model. Note that in
48  // theory the minimum required number of samples is 6 but Laurent Kneip
49  // showed in his paper that using 8 samples is more stable.
50  static const int kMinNumSamples = 8;
51 
52  // Estimate the most probable solution of the GR6P problem from a set of
53  // six 2D-2D point correspondences.
54  static std::vector<M_t> Estimate(const std::vector<X_t>& points1,
55  const std::vector<Y_t>& points2);
56 
57  // Calculate the squared Sampson error between corresponding points.
58  static void Residuals(const std::vector<X_t>& points1,
59  const std::vector<Y_t>& points2,
60  const M_t& proj_matrix,
61  std::vector<double>* residuals);
62 };
63 
64 } // namespace colmap
65 
66 // EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION_CUSTOM(colmap::GR6PEstimator::X_t)
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &proj_matrix, std::vector< double > *residuals)
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
Matrix< double, 3, 4 > Matrix3x4d
Definition: types.h:39