gtsam
Loading...
Searching...
No Matches
FundamentalMatrix.h
1/*
2 * @file FundamentalMatrix.h
3 * @brief FundamentalMatrix classes
4 * @author Frank Dellaert
5 * @date October 2024
6 */
7
8#pragma once
9
11#include <gtsam/geometry/EssentialMatrix.h>
12#include <gtsam/geometry/Rot3.h>
13#include <gtsam/geometry/Unit3.h>
14
15namespace gtsam {
16
29class GTSAM_EXPORT FundamentalMatrix {
30 private:
31 Rot3 U_;
32 double s_;
33 Rot3 V_;
34
35 public:
37 FundamentalMatrix() : U_(Rot3()), s_(1.0), V_(Rot3()) {}
38
45 FundamentalMatrix(const Matrix3& U, double s, const Matrix3& V);
46
55 FundamentalMatrix(const Matrix3& F);
56
69 FundamentalMatrix(const Matrix3& Ka, const EssentialMatrix& E,
70 const Matrix3& Kb)
71 : FundamentalMatrix(Ka.transpose().inverse() * E.matrix() *
72 Kb.inverse()) {}
73
84 FundamentalMatrix(const Matrix3& Ka, const Pose3& aPb, const Matrix3& Kb)
85 : FundamentalMatrix(Ka, EssentialMatrix::FromPose3(aPb), Kb) {}
86
88 Matrix3 matrix() const;
89
91 Vector3 epipolarLine(const Point2& p, OptionalJacobian<3, 7> H = {});
92
96 void print(const std::string& s = "") const;
97
100 bool equals(const FundamentalMatrix& other, double tol = 1e-9) const;
102
105 inline constexpr static auto dimension = 7; // 3 for U, 1 for s, 3 for V
106 inline static size_t Dim() { return dimension; }
107 inline size_t dim() const { return dimension; }
108
110 Vector localCoordinates(const FundamentalMatrix& F) const;
111
113 FundamentalMatrix retract(const Vector& delta) const;
115 private:
117 FundamentalMatrix(const Rot3& U, double s, const Rot3& V)
118 : U_(U), s_(s), V_(V) {}
119
121 void initialize(Matrix3 U, double s, Matrix3 V);
122};
123
132class GTSAM_EXPORT SimpleFundamentalMatrix {
133 private:
134 EssentialMatrix E_;
135 double fa_;
136 double fb_;
137 Point2 ca_;
138 Point2 cb_;
139
141 Matrix3 Ka() const;
142
144 Matrix3 Kb() const;
145
146 public:
149 : E_(), fa_(1.0), fb_(1.0), ca_(0.0, 0.0), cb_(0.0, 0.0) {}
150
160 double fa, double fb, const Point2& ca,
161 const Point2& cb)
162 : E_(E), fa_(fa), fb_(fb), ca_(ca), cb_(cb) {}
163
166 Matrix3 matrix() const;
167
169 Vector3 epipolarLine(const Point2& p, OptionalJacobian<3, 7> H = {});
170
174 void print(const std::string& s = "") const;
175
177 bool equals(const SimpleFundamentalMatrix& other, double tol = 1e-9) const;
179
182 inline constexpr static auto dimension = 7; // 5 for E, 1 for fa, 1 for fb
183 inline static size_t Dim() { return dimension; }
184 inline size_t dim() const { return dimension; }
185
187 Vector localCoordinates(const SimpleFundamentalMatrix& F) const;
188
190 SimpleFundamentalMatrix retract(const Vector& delta) const;
192};
193
200GTSAM_EXPORT Point2 EpipolarTransfer(const Matrix3& Fca, const Point2& pa,
201 const Matrix3& Fcb, const Point2& pb);
202
205template <typename F>
206struct TripleF {
207 F Fab, Fbc, Fca;
208
210 Point2 transferToA(const Point2& pb, const Point2& pc) {
211 return EpipolarTransfer(Fab.matrix(), pb, Fca.matrix().transpose(), pc);
212 }
213
215 Point2 transferToB(const Point2& pa, const Point2& pc) {
216 return EpipolarTransfer(Fab.matrix().transpose(), pa, Fbc.matrix(), pc);
217 }
218
220 Point2 transferToC(const Point2& pa, const Point2& pb) {
221 return EpipolarTransfer(Fca.matrix(), pa, Fbc.matrix().transpose(), pb);
222 }
223};
224
225template <>
227 : public internal::Manifold<FundamentalMatrix> {};
228
229template <>
231 : public internal::Manifold<SimpleFundamentalMatrix> {};
232
233} // namespace gtsam
Special class for optional Jacobian arguments.
3D rotation represented as a rotation matrix or quaternion
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector2 Point2
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point2 to Vector2...
Definition Point2.h:32
Point2 EpipolarTransfer(const Matrix3 &Fca, const Point2 &pa, const Matrix3 &Fcb, const Point2 &pb)
Transfer projections from cameras a and b to camera c.
Definition FundamentalMatrix.cpp:15
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Both ManifoldTraits and Testable.
Definition Manifold.h:156
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
An essential matrix is like a Pose3, except with translation up to scale It is named after the 3*3 ma...
Definition EssentialMatrix.h:26
Represents a fundamental matrix in computer vision, which encodes the epipolar geometry between two v...
Definition FundamentalMatrix.h:29
Matrix3 matrix() const
Return the fundamental matrix representation.
Definition FundamentalMatrix.cpp:77
FundamentalMatrix()
Default constructor.
Definition FundamentalMatrix.h:37
FundamentalMatrix(const Matrix3 &Ka, const EssentialMatrix &E, const Matrix3 &Kb)
Construct from essential matrix and calibration matrices.
Definition FundamentalMatrix.h:69
FundamentalMatrix(const Matrix3 &Ka, const Pose3 &aPb, const Matrix3 &Kb)
Construct from calibration matrices Ka, Kb, and pose aPb.
Definition FundamentalMatrix.h:84
Class for representing a simple fundamental matrix.
Definition FundamentalMatrix.h:132
SimpleFundamentalMatrix(const EssentialMatrix &E, double fa, double fb, const Point2 &ca, const Point2 &cb)
Construct from essential matrix and focal lengths.
Definition FundamentalMatrix.h:159
SimpleFundamentalMatrix()
Default constructor.
Definition FundamentalMatrix.h:148
Represents a set of three fundamental matrices for transferring points between three cameras.
Definition FundamentalMatrix.h:206
Point2 transferToC(const Point2 &pa, const Point2 &pb)
Transfers a point from cameras a,b to camera c.
Definition FundamentalMatrix.h:220
Point2 transferToA(const Point2 &pb, const Point2 &pc)
Transfers a point from cameras b,c to camera a.
Definition FundamentalMatrix.h:210
Point2 transferToB(const Point2 &pa, const Point2 &pc)
Transfers a point from camera a,c to camera b.
Definition FundamentalMatrix.h:215
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65