gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StereoCamera.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 
18 #pragma once
19 
20 #include <boost/tuple/tuple.hpp>
21 
22 #include <gtsam/base/DerivedValue.h>
24 #include <gtsam/geometry/Pose3.h>
26 
27 namespace gtsam {
28 
29 class GTSAM_EXPORT StereoCheiralityException: public std::runtime_error {
30 public:
31  StereoCheiralityException() : std::runtime_error("Stereo Cheirality Exception") {}
32 };
33 
34 
39 class GTSAM_EXPORT StereoCamera : public DerivedValue<StereoCamera> {
40 
41 private:
42  Pose3 leftCamPose_;
44 
45 public:
46 
49 
50  StereoCamera() {
51  }
52 
53  StereoCamera(const Pose3& leftCamPose, const Cal3_S2Stereo::shared_ptr K);
54 
55  const Cal3_S2Stereo::shared_ptr calibration() const {
56  return K_;
57  }
58 
62 
63  void print(const std::string& s = "") const {
64  leftCamPose_.print(s + ".camera.");
65  K_->print(s + ".calibration.");
66  }
67 
68  bool equals(const StereoCamera &camera, double tol = 1e-9) const {
69  return leftCamPose_.equals(camera.leftCamPose_, tol) && K_->equals(
70  *camera.K_, tol);
71  }
72 
76 
78  inline size_t dim() const {
79  return 6;
80  }
81 
83  static inline size_t Dim() {
84  return 6;
85  }
86 
88  inline StereoCamera retract(const Vector& v) const {
89  return StereoCamera(pose().retract(v), K_);
90  }
91 
93  inline Vector localCoordinates(const StereoCamera& t2) const {
94  return Vector(leftCamPose_.localCoordinates(t2.leftCamPose_));
95  }
96 
97  Pose3 between(const StereoCamera &camera,
98  boost::optional<Matrix&> H1=boost::none,
99  boost::optional<Matrix&> H2=boost::none) const {
100  return leftCamPose_.between(camera.pose(), H1, H2);
101  }
102 
106 
107  const Pose3& pose() const {
108  return leftCamPose_;
109  }
110 
111  double baseline() const {
112  return K_->baseline();
113  }
114 
115  /*
116  * project 3D point and compute optional derivatives
117  */
118  StereoPoint2 project(const Point3& point,
119  boost::optional<Matrix&> H1 = boost::none,
120  boost::optional<Matrix&> H2 = boost::none) const;
121 
122  /*
123  * to accomodate tsam's assumption that K is estimated, too
124  */
125  StereoPoint2 project(const Point3& point,
126  boost::optional<Matrix&> H1,
127  boost::optional<Matrix&> H1_k,
128  boost::optional<Matrix&> H2) const {
129  return project(point, H1, H2);
130  }
131 
132  Point3 backproject(const StereoPoint2& z) const {
133  Vector measured = z.vector();
134  double Z = K_->baseline()*K_->fx()/(measured[0]-measured[1]);
135  double X = Z *(measured[0]- K_->px()) / K_->fx();
136  double Y = Z *(measured[2]- K_->py()) / K_->fy();
137  Point3 world_point = leftCamPose_.transform_from(Point3(X, Y, Z));
138  return world_point;
139  }
140 
142 
143 private:
145  Matrix Dproject_to_stereo_camera1(const Point3& P) const;
146 
147  friend class boost::serialization::access;
148  template<class Archive>
149  void serialize(Archive & ar, const unsigned int version) {
150  ar & boost::serialization::make_nvp("StereoCamera",
151  boost::serialization::base_object<Value>(*this));
152  ar & BOOST_SERIALIZATION_NVP(leftCamPose_);
153  ar & BOOST_SERIALIZATION_NVP(K_);
154  }
155 
156 };
157 
158 }
The most common 5DOF 3D->2D calibration + Stereo baseline.
boost::shared_ptr< Cal3_S2Stereo > shared_ptr
shared pointer to stereo calibration object
Definition: Cal3_S2Stereo.h:37
Vector localCoordinates(const StereoCamera &t2) const
Local coordinates of manifold neighborhood around current value.
Definition: StereoCamera.h:93
Definition: Pose3.h:42
StereoCamera retract(const Vector &v) const
Updates a with tangent space delta.
Definition: StereoCamera.h:88
A 2D stereo point (uL,uR,v)
Definition: StereoCamera.h:29
Template to create a binary predicate.
Definition: Testable.h:102
static size_t Dim()
Dimensionality of the tangent space.
Definition: StereoCamera.h:83
size_t dim() const
Dimensionality of the tangent space.
Definition: StereoCamera.h:78
3D Pose
void print(const std::string &s="") const
Print this value, for debugging and unit tests.
Definition: StereoCamera.h:63
Definition: StereoCamera.h:39
Definition: DerivedValue.h:44