ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
essential_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 <ceres/ceres.h>
11 
12 #include <Eigen/Core>
13 #include <vector>
14 
15 #include "util/alignment.h"
16 #include "util/types.h"
17 
18 namespace colmap {
19 
20 // Decompose an essential matrix into the possible rotations and translations.
21 //
22 // The first pose is assumed to be P = [I | 0] and the set of four other
23 // possible second poses are defined as: {[R1 | t], [R2 | t],
24 // [R1 | -t], [R2 | -t]}
25 //
26 // @param E 3x3 essential matrix.
27 // @param R1 First possible 3x3 rotation matrix.
28 // @param R2 Second possible 3x3 rotation matrix.
29 // @param t 3x1 possible translation vector (also -t possible).
30 void DecomposeEssentialMatrix(const Eigen::Matrix3d& E,
31  Eigen::Matrix3d* R1,
32  Eigen::Matrix3d* R2,
33  Eigen::Vector3d* t);
34 
35 // Recover the most probable pose from the given essential matrix.
36 //
37 // The pose of the first image is assumed to be P = [I | 0].
38 //
39 // @param E 3x3 essential matrix.
40 // @param points1 First set of corresponding points.
41 // @param points2 Second set of corresponding points.
42 // @param inlier_mask Only points with `true` in the inlier mask are
43 // considered in the cheirality test. Size of the
44 // inlier mask must match the number of points N.
45 // @param R Most probable 3x3 rotation matrix.
46 // @param t Most probable 3x1 translation vector.
47 // @param points3D Triangulated 3D points infront of camera.
48 void PoseFromEssentialMatrix(const Eigen::Matrix3d& E,
49  const std::vector<Eigen::Vector2d>& points1,
50  const std::vector<Eigen::Vector2d>& points2,
51  Eigen::Matrix3d* R,
52  Eigen::Vector3d* t,
53  std::vector<Eigen::Vector3d>* points3D);
54 
55 // Compose essential matrix from relative camera poses.
56 //
57 // Assumes that first camera pose has projection matrix P = [I | 0], and
58 // pose of second camera is given as transformation from world to camera system.
59 //
60 // @param R 3x3 rotation matrix.
61 // @param t 3x1 translation vector.
62 //
63 // @return 3x3 essential matrix.
64 Eigen::Matrix3d EssentialMatrixFromPose(const Eigen::Matrix3d& R,
65  const Eigen::Vector3d& t);
66 
67 // Compose essential matrix from two absolute camera poses.
68 //
69 // @param proj_matrix1 3x4 projection matrix.
70 // @param proj_matrix2 3x4 projection matrix.
71 //
72 // @return 3x3 essential matrix.
73 Eigen::Matrix3d EssentialMatrixFromAbsolutePoses(
74  const Eigen::Matrix3x4d& proj_matrix1,
75  const Eigen::Matrix3x4d& proj_matrix2);
76 
77 // Find optimal image points, such that:
78 //
79 // optimal_point1^t * E * optimal_point2 = 0
80 //
81 // as described in:
82 //
83 // Lindstrom, P., "Triangulation made easy",
84 // Computer Vision and Pattern Recognition (CVPR),
85 // 2010 IEEE Conference on , vol., no., pp.1554,1561, 13-18 June 2010
86 //
87 // @param E Essential or fundamental matrix.
88 // @param point1 Corresponding 2D point in first image.
89 // @param point2 Corresponding 2D point in second image.
90 // @param optimal_point1 Estimated optimal image point in the first image.
91 // @param optimal_point2 Estimated optimal image point in the second image.
92 void FindOptimalImageObservations(const Eigen::Matrix3d& E,
93  const Eigen::Vector2d& point1,
94  const Eigen::Vector2d& point2,
95  Eigen::Vector2d* optimal_point1,
96  Eigen::Vector2d* optimal_point2);
97 
98 // Compute the location of the epipole in homogeneous coordinates.
99 //
100 // @param E 3x3 essential matrix.
101 // @param left_image If true, epipole in left image is computed,
102 // else in right image.
103 //
104 // @return Epipole in homogeneous coordinates.
105 Eigen::Vector3d EpipoleFromEssentialMatrix(const Eigen::Matrix3d& E,
106  const bool left_image);
107 
108 // Invert the essential matrix, i.e. if the essential matrix E describes the
109 // transformation from camera A to B, the inverted essential matrix E' describes
110 // the transformation from camera B to A.
111 //
112 // @param E 3x3 essential matrix.
113 //
114 // @return Inverted essential matrix.
115 Eigen::Matrix3d InvertEssentialMatrix(const Eigen::Matrix3d& matrix);
116 
117 // Refine essential matrix.
118 //
119 // Decomposes the essential matrix into rotation and translation components
120 // and refines the relative pose using the function `RefineRelativePose`.
121 //
122 // @param E 3x3 essential matrix.
123 // @param points1 First set of corresponding points.
124 // @param points2 Second set of corresponding points.
125 // @param inlier_mask Inlier mask for corresponding points.
126 // @param options Solver options.
127 //
128 // @return Flag indicating if solution is usable.
129 bool RefineEssentialMatrix(const ceres::Solver::Options& options,
130  const std::vector<Eigen::Vector2d>& points1,
131  const std::vector<Eigen::Vector2d>& points2,
132  const std::vector<char>& inlier_mask,
133  Eigen::Matrix3d* E);
134 
135 } // namespace colmap
Matrix< double, 3, 4 > Matrix3x4d
Definition: types.h:39
Eigen::Matrix3d InvertEssentialMatrix(const Eigen::Matrix3d &E)
Eigen::Matrix3d EssentialMatrixFromAbsolutePoses(const Eigen::Matrix3x4d &proj_matrix1, const Eigen::Matrix3x4d &proj_matrix2)
void FindOptimalImageObservations(const Eigen::Matrix3d &E, const Eigen::Vector2d &point1, const Eigen::Vector2d &point2, Eigen::Vector2d *optimal_point1, Eigen::Vector2d *optimal_point2)
Eigen::Matrix3d EssentialMatrixFromPose(const Eigen::Matrix3d &R, const Eigen::Vector3d &t)
void DecomposeEssentialMatrix(const Eigen::Matrix3d &E, Eigen::Matrix3d *R1, Eigen::Matrix3d *R2, Eigen::Vector3d *t)
Eigen::Vector3d EpipoleFromEssentialMatrix(const Eigen::Matrix3d &E, const bool left_image)
void PoseFromEssentialMatrix(const Eigen::Matrix3d &E, const std::vector< Eigen::Vector2d > &points1, const std::vector< Eigen::Vector2d > &points2, Eigen::Matrix3d *R, Eigen::Vector3d *t, std::vector< Eigen::Vector3d > *points3D)
bool RefineEssentialMatrix(const ceres::Solver::Options &options, const std::vector< Eigen::Vector2d > &points1, const std::vector< Eigen::Vector2d > &points2, const std::vector< char > &inlier_mask, Eigen::Matrix3d *E)