ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
homography_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 
13 #include "util/alignment.h"
14 #include "util/types.h"
15 
16 namespace colmap {
17 
18 // Decompose an homography matrix into the possible rotations, translations,
19 // and plane normal vectors, according to:
20 //
21 // Malis, Ezio, and Manuel Vargas. "Deeper understanding of the homography
22 // decomposition for vision-based control." (2007): 90.
23 //
24 // The first pose is assumed to be P = [I | 0]. Note that the homography is
25 // plane-induced if `R.size() == t.size() == n.size() == 4`. If `R.size() ==
26 // t.size() == n.size() == 1` the homography is pure-rotational.
27 //
28 // @param H 3x3 homography matrix.
29 // @param K 3x3 calibration matrix.
30 // @param R Possible 3x3 rotation matrices.
31 // @param t Possible translation vectors.
32 // @param n Possible normal vectors.
33 void DecomposeHomographyMatrix(const Eigen::Matrix3d& H,
34  const Eigen::Matrix3d& K1,
35  const Eigen::Matrix3d& K2,
36  std::vector<Eigen::Matrix3d>* R,
37  std::vector<Eigen::Vector3d>* t,
38  std::vector<Eigen::Vector3d>* n);
39 
40 // Recover the most probable pose from the given homography matrix.
41 //
42 // The pose of the first image is assumed to be P = [I | 0].
43 //
44 // @param H 3x3 homography matrix.
45 // @param K1 3x3 calibration matrix of first camera.
46 // @param K2 3x3 calibration matrix of second camera.
47 // @param points1 First set of corresponding points.
48 // @param points2 Second set of corresponding points.
49 // @param inlier_mask Only points with `true` in the inlier mask are
50 // considered in the cheirality test. Size of the
51 // inlier mask must match the number of points N.
52 // @param R Most probable 3x3 rotation matrix.
53 // @param t Most probable 3x1 translation vector.
54 // @param n Most probable 3x1 normal vector.
55 // @param points3D Triangulated 3D points infront of camera
56 // (only if homography is not pure-rotational).
57 void PoseFromHomographyMatrix(const Eigen::Matrix3d& H,
58  const Eigen::Matrix3d& K1,
59  const Eigen::Matrix3d& K2,
60  const std::vector<Eigen::Vector2d>& points1,
61  const std::vector<Eigen::Vector2d>& points2,
62  Eigen::Matrix3d* R,
63  Eigen::Vector3d* t,
64  Eigen::Vector3d* n,
65  std::vector<Eigen::Vector3d>* points3D);
66 
67 // Compose homography matrix from relative pose.
68 //
69 // @param K1 3x3 calibration matrix of first camera.
70 // @param K2 3x3 calibration matrix of second camera.
71 // @param R Most probable 3x3 rotation matrix.
72 // @param t Most probable 3x1 translation vector.
73 // @param n Most probable 3x1 normal vector.
74 // @param d Orthogonal distance from plane.
75 //
76 // @return 3x3 homography matrix.
77 Eigen::Matrix3d HomographyMatrixFromPose(const Eigen::Matrix3d& K1,
78  const Eigen::Matrix3d& K2,
79  const Eigen::Matrix3d& R,
80  const Eigen::Vector3d& t,
81  const Eigen::Vector3d& n,
82  const double d);
83 
84 } // namespace colmap
types.h
colmap::MinSTGraphCut::AddEdge
void AddEdge(const node_t node_idx1, const node_t node_idx2, const value_t capacity, const value_t reverse_capacity)
Definition: graph_cut.h:142
colmap::MinSTGraphCut
Definition: graph_cut.h:40
colmap::MinSTGraphCut::AddNode
void AddNode(const node_t node_idx, const value_t source_capacity, const value_t sink_capacity)
Definition: graph_cut.h:112
colmap::DecomposeHomographyMatrix
void DecomposeHomographyMatrix(const Eigen::Matrix3d &H, const Eigen::Matrix3d &K1, const Eigen::Matrix3d &K2, std::vector< Eigen::Matrix3d > *R, std::vector< Eigen::Vector3d > *t, std::vector< Eigen::Vector3d > *n)
Definition: homography_matrix.cc:65
alignment.h
graph_cut.h
colmap::CenterAndNormalizeImagePoints
void CenterAndNormalizeImagePoints(const std::vector< Eigen::Vector2d > &points, std::vector< Eigen::Vector2d > *normed_points, Eigen::Matrix3d *matrix)
Definition: utils.cc:38
colmap::ComputeMinGraphCutStoerWagner
void ComputeMinGraphCutStoerWagner(const std::vector< std::pair< int, int >> &edges, const std::vector< int > &weights, int *cut_weight, std::vector< char > *cut_labels)
Definition: graph_cut.cc:150
testing.h
projection.h
math.h
colmap::MinSTGraphCut::NumEdges
size_t NumEdges() const
Definition: graph_cut.h:107
homography_matrix.h
e
const double * e
Definition: essential_matrix_poly.h:10
colmap::ComputeNormalizedMinGraphCut
std::unordered_map< int, int > ComputeNormalizedMinGraphCut(const std::vector< std::pair< int, int >> &edges, const std::vector< int > &weights, const int num_parts)
Definition: graph_cut.cc:186
colmap::MinSTGraphCut::IsConnectedToSink
bool IsConnectedToSink(const node_t node_idx) const
Definition: graph_cut.h:186
colmap::HomographyMatrixEstimator::M_t
Eigen::Matrix3d M_t
Definition: homography_matrix.h:25
colmap::SignOfNumber
int SignOfNumber(const T val)
Definition: math.h:156
colmap::CheckCheirality
bool CheckCheirality(const Eigen::Matrix3d &R, const Eigen::Vector3d &t, const std::vector< Eigen::Vector2d > &points1, const std::vector< Eigen::Vector2d > &points2, std::vector< Eigen::Vector3d > *points3D)
Definition: pose.cc:225
colmap::HomographyMatrixEstimator::Estimate
static std::vector< M_t > Estimate(const std::vector< X_t > &points1, const std::vector< Y_t > &points2)
Definition: homography_matrix.cc:44
homography_matrix.h
colmap::MinSTGraphCut::Compute
value_t Compute()
Definition: graph_cut.h:164
pose.h
logging.h
colmap::HomographyMatrixFromPose
Eigen::Matrix3d HomographyMatrixFromPose(const Eigen::Matrix3d &K1, const Eigen::Matrix3d &K2, const Eigen::Matrix3d &R, const Eigen::Vector3d &t, const Eigen::Vector3d &n, const double d)
Definition: homography_matrix.cc:214
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(TestComputeMinGraphCutStoerWagner)
Definition: graph_cut_test.cc:39
colmap
Definition: AutomaticReconstructionController.h:17
colmap::MinSTGraphCut::IsConnectedToSource
bool IsConnectedToSource(const node_t node_idx) const
Definition: graph_cut.h:180
colmap::MinSTGraphCut::NumNodes
size_t NumNodes() const
Definition: graph_cut.h:102
Utils::distance
static double distance(T *pot1, T *pot2)
Definition: utils.h:111
utils.h
colmap::HomographyMatrixEstimator::Residuals
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &H, std::vector< double > *residuals)
Definition: homography_matrix.cc:94
colmap::PoseFromHomographyMatrix
void PoseFromHomographyMatrix(const Eigen::Matrix3d &H, const Eigen::Matrix3d &K1, const Eigen::Matrix3d &K2, const std::vector< Eigen::Vector2d > &points1, const std::vector< Eigen::Vector2d > &points2, Eigen::Matrix3d *R, Eigen::Vector3d *t, Eigen::Vector3d *n, std::vector< Eigen::Vector3d > *points3D)
Definition: homography_matrix.cc:186