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)
static std::vector< M_t > Estimate(const std::vector< X_t > &points2D, const std::vector< Y_t > &points3D)
void Residuals(const std::vector< X_t > &points2D, const std::vector< Y_t > &points3D, const M_t &proj_matrix, std::vector< double > *residuals)
Matrix< double, 3, 4 > Matrix3x4d
Definition: types.h:39