Cal3.cpp
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 
18 #include <gtsam/geometry/Cal3.h>
19 
20 #include <cmath>
21 #include <fstream>
22 #include <iostream>
23 
24 namespace gtsam {
25 
26 /* ************************************************************************* */
27 Cal3::Cal3(double fov, int w, int h)
28  : s_(0), u0_((double)w / 2.0), v0_((double)h / 2.0) {
29  double a = fov * M_PI / 360.0; // fov/2 in radians
30  fx_ = double(w) / (2.0 * tan(a));
31  fy_ = fx_;
32 }
33 
34 /* ************************************************************************* */
35 Cal3::Cal3(const std::string& path) {
36  const auto buffer = path + std::string("/calibration_info.txt");
37  std::ifstream infile(buffer, std::ios::in);
38 
39  if (infile && !infile.eof()) {
40  infile >> fx_ >> fy_ >> s_ >> u0_ >> v0_;
41  } else {
42  throw std::runtime_error("Cal3: Unable to load the calibration");
43  }
44 
45  infile.close();
46 }
47 
48 /* ************************************************************************* */
49 std::ostream& operator<<(std::ostream& os, const Cal3& cal) {
50  os << "fx: " << cal.fx() << ", fy: " << cal.fy() << ", s: " << cal.skew()
51  << ", px: " << cal.px() << ", py: " << cal.py();
52  return os;
53 }
54 
55 /* ************************************************************************* */
56 void Cal3::print(const std::string& s) const { gtsam::print((Matrix)K(), s); }
57 
58 /* ************************************************************************* */
59 bool Cal3::equals(const Cal3& K, double tol) const {
60  return (std::fabs(fx_ - K.fx_) < tol && std::fabs(fy_ - K.fy_) < tol &&
61  std::fabs(s_ - K.s_) < tol && std::fabs(u0_ - K.u0_) < tol &&
62  std::fabs(v0_ - K.v0_) < tol);
63 }
64 
65 Matrix3 Cal3::inverse() const {
66  const double fxy = fx_ * fy_, sv0 = s_ * v0_, fyu0 = fy_ * u0_;
67  Matrix3 K_inverse;
68  K_inverse << 1.0 / fx_, -s_ / fxy, (sv0 - fyu0) / fxy, 0.0, 1.0 / fy_,
69  -v0_ / fy_, 0.0, 0.0, 1.0;
70  return K_inverse;
71 }
72 
73 /* ************************************************************************* */
74 
75 } // \ namespace gtsam
gtsam::Cal3::fy
double fy() const
focal length y
Definition: Cal3.h:142
gtsam::Cal3::fx_
double fx_
Definition: Cal3.h:71
w
RowVector3d w
Definition: Matrix_resize_int.cpp:3
fov
static double fov
Definition: testProjectionFactor.cpp:33
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::operator<<
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
Definition: testGroup.cpp:109
gtsam::Cal3::inverse
Matrix3 inverse() const
Return inverted calibration matrix inv(K)
Definition: Cal3.cpp:65
Cal3.h
Common code for all Calibration models.
gtsam::Cal3::print
virtual void print(const std::string &s="") const
print with optional string
Definition: Cal3.cpp:56
gtsam::Cal3::py
double py() const
image center in y
Definition: Cal3.h:154
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
buffer
Definition: pytypes.h:2270
h
const double h
Definition: testSimpleHelicopter.cpp:19
os
ofstream os("timeSchurFactors.csv")
gtsam::Cal3::u0_
double u0_
Definition: Cal3.h:73
fixture::cal
const Cal3_S2 cal(focalLength, focalLength, 0.0, principalPoint.x(), principalPoint.y())
boost::multiprecision::fabs
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:119
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
gtsam::Cal3::Cal3
Cal3()=default
Create a default calibration that leaves coordinates unchanged.
gtsam::Cal3
Common base class for all calibration models.
Definition: Cal3.h:69
gtsam::Cal3::fy_
double fy_
focal length
Definition: Cal3.h:71
gtsam::Cal3::K
virtual Matrix3 K() const
return calibration matrix K
Definition: Cal3.h:167
tan
const EIGEN_DEVICE_FUNC TanReturnType tan() const
Definition: ArrayCwiseUnaryOps.h:269
matlab_wrap.path
path
Definition: matlab_wrap.py:66
gtsam::Cal3::equals
bool equals(const Cal3 &K, double tol=10e-9) const
Check if equal up to specified tolerance.
Definition: Cal3.cpp:59
gtsam::Cal3::fx
double fx() const
focal length x
Definition: Cal3.h:139
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition: SFMdata.h:40
K
#define K
Definition: igam.h:8
gtsam::Cal3::skew
double skew() const
skew
Definition: Cal3.h:148
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Cal3::px
double px() const
image center in x
Definition: Cal3.h:151
M_PI
#define M_PI
Definition: mconf.h:117
gtsam::Cal3::s_
double s_
skew
Definition: Cal3.h:72
gtsam::Cal3::v0_
double v0_
principal point
Definition: Cal3.h:73


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:56