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
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)
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)
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)