gtsam
Loading...
Searching...
No Matches
Cal3.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
17
21
22#pragma once
23
25
26namespace gtsam {
27
46template <typename Cal, size_t Dim>
47void calibrateJacobians(const Cal& calibration, const Point2& pn,
49 OptionalJacobian<2, 2> Dp = {}) {
50 if (Dcal || Dp) {
51 Eigen::Matrix<double, 2, Dim> H_uncal_K;
52 Matrix22 H_uncal_pn, H_uncal_pn_inv;
53
54 // Compute uncalibrate Jacobians
55 calibration.uncalibrate(pn, Dcal ? &H_uncal_K : nullptr, H_uncal_pn);
56
57 H_uncal_pn_inv = H_uncal_pn.inverse();
58
59 if (Dp) *Dp = H_uncal_pn_inv;
60 if (Dcal) *Dcal = -H_uncal_pn_inv * H_uncal_K;
61 }
62}
63
69class GTSAM_EXPORT Cal3 {
70 protected:
71 double fx_ = 1.0f, fy_ = 1.0f;
72 double s_ = 0.0f;
73 double u0_ = 0.0f, v0_ = 0.0f;
74
75 public:
77 using shared_ptr = std::shared_ptr<Cal3>;
78
81
83 Cal3() = default;
84
86 Cal3(double fx, double fy, double s, double u0, double v0)
87 : fx_(fx), fy_(fy), s_(s), u0_(u0), v0_(v0) {}
88
90 Cal3(const Vector5& d)
91 : fx_(d(0)), fy_(d(1)), s_(d(2)), u0_(d(3)), v0_(d(4)) {}
92
99 Cal3(double fov, int w, int h);
100
102 virtual ~Cal3() {}
103
107
117 Cal3(const std::string& path);
118
122
124 GTSAM_EXPORT friend std::ostream& operator<<(std::ostream& os,
125 const Cal3& cal);
126
128 virtual void print(const std::string& s = "") const;
129
131 bool equals(const Cal3& K, double tol = 10e-9) const;
132
136
138 double fx() const { return fx_; }
139
141 double fy() const { return fy_; }
142
144 double aspectRatio() const { return fx_ / fy_; }
145
147 double skew() const { return s_; }
148
150 double px() const { return u0_; }
151
153 double py() const { return v0_; }
154
156 Point2 principalPoint() const { return Point2(u0_, v0_); }
157
159 Vector5 vector() const { return Vector5{fx_, fy_, s_, u0_, v0_}; }
160
162 virtual Matrix3 K() const {
163 return Matrix3{{fx_, s_, u0_}, {0.0, fy_, v0_}, {0.0, 0.0, 1.0}};
164 }
165
167 Matrix3 inverse() const;
168
172
173 private:
174#if GTSAM_ENABLE_BOOST_SERIALIZATION
176 friend class boost::serialization::access;
177 template <class Archive>
178 void serialize(Archive& ar, const unsigned int /*version*/) {
179 ar& BOOST_SERIALIZATION_NVP(fx_);
180 ar& BOOST_SERIALIZATION_NVP(fy_);
181 ar& BOOST_SERIALIZATION_NVP(s_);
182 ar& BOOST_SERIALIZATION_NVP(u0_);
183 ar& BOOST_SERIALIZATION_NVP(v0_);
184 }
185#endif
186
188};
189
190} // \ namespace gtsam
2D Point
Global functions in a separate testing namespace.
Definition chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
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
void calibrateJacobians(const Cal &calibration, const Point2 &pn, OptionalJacobian< 2, Dim > Dcal={}, OptionalJacobian< 2, 2 > Dp={})
Function which makes use of the Implicit Function Theorem to compute the Jacobians of calibrate using...
Definition Cal3.h:47
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
Template to create a binary predicate.
Definition Testable.h:112
Common base class for all calibration models.
Definition Cal3.h:69
Cal3(double fx, double fy, double s, double u0, double v0)
constructor from doubles
Definition Cal3.h:86
virtual Matrix3 K() const
return calibration matrix K
Definition Cal3.h:162
Cal3(const Vector5 &d)
constructor from vector
Definition Cal3.h:90
virtual ~Cal3()
Virtual destructor.
Definition Cal3.h:102
Vector5 vector() const
vectorized form (column-wise)
Definition Cal3.h:159
Cal3()=default
Create a default calibration that leaves coordinates unchanged.
double fy_
focal length
Definition Cal3.h:71
double px() const
image center in x
Definition Cal3.h:150
double s_
skew
Definition Cal3.h:72
std::shared_ptr< Cal3 > shared_ptr
< shared pointer to calibration object
Definition Cal3.h:77
Point2 principalPoint() const
return the principal point
Definition Cal3.h:156
double fx() const
focal length x
Definition Cal3.h:138
double py() const
image center in y
Definition Cal3.h:153
double skew() const
skew
Definition Cal3.h:147
double aspectRatio() const
aspect ratio
Definition Cal3.h:144
double v0_
principal point
Definition Cal3.h:73
double fy() const
focal length y
Definition Cal3.h:141