ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
generalized_absolute_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 P3P problem (NP3P or GP3P), based on:
19 //
20 // Lee, Gim Hee, et al. "Minimal solutions for pose estimation of a
21 // multi-camera system." Robotics Research. Springer International
22 // Publishing, 2016. 521-538.
23 //
24 // This class is based on an original implementation by Federico Camposeco.
26 public:
27  // The generalized image observations, which is composed of the relative
28  // pose of the specific camera in the generalized camera and its image
29  // observation.
30  struct X_t {
31  // The relative transformation from the generalized camera to the camera
32  // frame of the observation.
34  // The 2D image feature observation.
35  Eigen::Vector2d xy;
36  };
37 
38  // The observed 3D feature points in the world frame.
39  typedef Eigen::Vector3d Y_t;
40  // The transformation from the world to the generalized camera frame.
42 
43  // The minimum number of samples needed to estimate a model.
44  static const int kMinNumSamples = 3;
45 
46  enum class ResidualType {
49  };
50 
51  // Whether to compute the cosine similarity or the reprojection error.
52  // [WARNING] The reprojection error being in normalized coordinates,
53  // the unique error threshold of RANSAC corresponds to different pixel
54  // values in the different cameras of the rig if they have different
55  // intrinsics.
57 
58  // Estimate the most probable solution of the GP3P problem from a set of
59  // three 2D-3D point correspondences.
60  static std::vector<M_t> Estimate(const std::vector<X_t>& points2D,
61  const std::vector<Y_t>& points3D);
62 
63  // Calculate the squared cosine distance error between the rays given a set
64  // of 2D-3D point correspondences and a projection matrix of the generalized
65  // camera.
66  void Residuals(const std::vector<X_t>& points2D,
67  const std::vector<Y_t>& points3D,
68  const M_t& proj_matrix,
69  std::vector<double>* residuals);
70 };
71 
72 } // namespace colmap
73 
74 // EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION_CUSTOM(colmap::GP3PEstimator::X_t)
colmap::GP3PEstimator::X_t
Definition: generalized_absolute_pose.h:30
types.h
colmap::GP3PEstimator::Y_t
Eigen::Vector3d Y_t
Definition: generalized_absolute_pose.h:39
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
generalized_absolute_pose_coeffs.h
Eigen::Matrix3x4d
Matrix< double, 3, 4 > Matrix3x4d
Definition: types.h:39
polynomial.h
alignment.h
Eigen::Vector6d
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: Eigen.h:107
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
generalized_absolute_pose.h
colmap::FindPolynomialRootsCompanionMatrix
bool FindPolynomialRootsCompanionMatrix(const Eigen::VectorXd &coeffs_all, Eigen::VectorXd *real, Eigen::VectorXd *imag)
Definition: polynomial.cc:208
testing.h
projection.h
colmap::InvertProjectionMatrix
Eigen::Matrix3x4d InvertProjectionMatrix(const Eigen::Matrix3x4d &proj_matrix)
Definition: projection.cc:55
colmap::FundamentalMatrixEightPointEstimator
Definition: fundamental_matrix.h:69
colmap::GP3PEstimator::residual_type
ResidualType residual_type
Definition: generalized_absolute_pose.h:56
colmap::ComputeDepthsSylvesterCoeffs
Eigen::Matrix< double, 9, 1 > ComputeDepthsSylvesterCoeffs(const Eigen::Matrix< double, 3, 6 > &K)
Definition: generalized_absolute_pose_coeffs.cc:36
colmap::GP3PEstimator::Residuals
void Residuals(const std::vector< X_t > &points2D, const std::vector< Y_t > &points3D, const M_t &proj_matrix, std::vector< double > *residuals)
Definition: generalized_absolute_pose.cc:267
e
const double * e
Definition: essential_matrix_poly.h:10
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(TestSevenPoint)
Definition: fundamental_matrix_test.cc:39
colmap::GP3PEstimator::kMinNumSamples
static const int kMinNumSamples
Definition: generalized_absolute_pose.h:44
colmap::GP3PEstimator::ResidualType::CosineDistance
@ CosineDistance
knncpp::Index
Eigen::MatrixXd::Index Index
Definition: knncpp.h:26
coeffs
coeffs(0)
colmap::GP3PEstimator::ResidualType::ReprojectionError
@ ReprojectionError
colmap::GP3PEstimator
Definition: generalized_absolute_pose.h:25
colmap::GP3PEstimator::X_t::rel_tform
Eigen::Matrix3x4d rel_tform
Definition: generalized_absolute_pose.h:33
colmap::FundamentalMatrixSevenPointEstimator
Definition: fundamental_matrix.h:27
fundamental_matrix.h
logging.h
colmap::GP3PEstimator::M_t
Eigen::Matrix3x4d M_t
Definition: generalized_absolute_pose.h:41
colmap
Definition: AutomaticReconstructionController.h:17
colmap::GP3PEstimator::X_t::xy
Eigen::Vector2d xy
Definition: generalized_absolute_pose.h:35
colmap::GP3PEstimator::ResidualType
ResidualType
Definition: generalized_absolute_pose.h:46
colmap::GP3PEstimator::Estimate
static std::vector< M_t > Estimate(const std::vector< X_t > &points2D, const std::vector< Y_t > &points3D)
Definition: generalized_absolute_pose.cc:211