gtsam  4.0.0
gtsam
CalibratedCamera.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 
19 #pragma once
20 
22 #include <gtsam/geometry/Point2.h>
23 #include <gtsam/geometry/Pose3.h>
24 #include <gtsam/base/concepts.h>
25 #include <gtsam/base/Manifold.h>
26 #include <gtsam/base/ThreadsafeException.h>
27 #include <gtsam/dllexport.h>
28 #include <boost/serialization/nvp.hpp>
29 
30 namespace gtsam {
31 
32 class GTSAM_EXPORT CheiralityException: public ThreadsafeException<
33  CheiralityException> {
34 public:
36  ThreadsafeException<CheiralityException>("Cheirality Exception") {
37  }
38 };
39 
45 class GTSAM_EXPORT PinholeBase {
46 
47 public:
48 
50  typedef Rot3 Rotation;
51  typedef Point3 Translation;
52 
58 
59 private:
60 
61  Pose3 pose_;
62 
63 protected:
64 
67 
73  static Matrix26 Dpose(const Point2& pn, double d);
74 
81  static Matrix23 Dpoint(const Point2& pn, double d, const Matrix3& Rt);
82 
84 
85 public:
86 
89 
97  static Pose3 LevelPose(const Pose2& pose2, double height);
98 
107  static Pose3 LookatPose(const Point3& eye, const Point3& target,
108  const Point3& upVector);
109 
113 
116  }
117 
119  explicit PinholeBase(const Pose3& pose) :
120  pose_(pose) {
121  }
122 
126 
127  explicit PinholeBase(const Vector &v) :
128  pose_(Pose3::Expmap(v)) {
129  }
130 
134 
136  bool equals(const PinholeBase &camera, double tol = 1e-9) const;
137 
139  void print(const std::string& s = "PinholeBase") const;
140 
144 
146  const Pose3& pose() const {
147  return pose_;
148  }
149 
151  const Rot3& rotation() const {
152  return pose_.rotation();
153  }
154 
156  const Point3& translation() const {
157  return pose_.translation();
158  }
159 
161  const Pose3& getPose(OptionalJacobian<6, 6> H) const;
162 
166 
172  static Point2 Project(const Point3& pc, //
173  OptionalJacobian<2, 3> Dpoint = boost::none);
174 
180  static Point2 Project(const Unit3& pc, //
181  OptionalJacobian<2, 2> Dpoint = boost::none);
182 
184  std::pair<Point2, bool> projectSafe(const Point3& pw) const;
185 
191  Point2 project2(const Point3& point, OptionalJacobian<2, 6> Dpose =
192  boost::none, OptionalJacobian<2, 3> Dpoint = boost::none) const;
193 
199  Point2 project2(const Unit3& point,
200  OptionalJacobian<2, 6> Dpose = boost::none,
201  OptionalJacobian<2, 2> Dpoint = boost::none) const;
202 
204  static Point3 backproject_from_camera(const Point2& p, const double depth);
205 
209 
215  inline static std::pair<size_t, size_t> translationInterval() {
216  return std::make_pair(3, 5);
217  }
218 
220 
221 private:
222 
224  friend class boost::serialization::access;
225  template<class Archive>
226  void serialize(Archive & ar, const unsigned int /*version*/) {
227  ar & BOOST_SERIALIZATION_NVP(pose_);
228  }
229 
230 };
231 // end of class PinholeBase
232 
240 class GTSAM_EXPORT CalibratedCamera: public PinholeBase {
241 
242 public:
243 
244  enum {
245  dimension = 6
246  };
247 
250 
253  }
254 
256  explicit CalibratedCamera(const Pose3& pose) :
257  PinholeBase(pose) {
258  }
259 
263 
264  // Create CalibratedCamera, with derivatives
265  static CalibratedCamera Create(const Pose3& pose,
266  OptionalJacobian<dimension, 6> H1 = boost::none) {
267  if (H1)
268  *H1 << I_6x6;
269  return CalibratedCamera(pose);
270  }
271 
278  static CalibratedCamera Level(const Pose2& pose2, double height);
279 
288  static CalibratedCamera Lookat(const Point3& eye, const Point3& target,
289  const Point3& upVector);
290 
294 
296  explicit CalibratedCamera(const Vector &v) :
297  PinholeBase(v) {
298  }
299 
303 
305  virtual ~CalibratedCamera() {
306  }
307 
311 
313  CalibratedCamera retract(const Vector& d) const;
314 
316  Vector localCoordinates(const CalibratedCamera& T2) const;
317 
319  inline size_t dim() const {
320  return 6;
321  }
322 
324  inline static size_t Dim() {
325  return 6;
326  }
327 
331 
336  Point2 project(const Point3& point, OptionalJacobian<2, 6> Dcamera =
337  boost::none, OptionalJacobian<2, 3> Dpoint = boost::none) const;
338 
340  Point3 backproject(const Point2& pn, double depth) const {
341  return pose().transform_from(backproject_from_camera(pn, depth));
342  }
343 
349  double range(const Point3& point,
350  OptionalJacobian<1, 6> Dcamera = boost::none,
351  OptionalJacobian<1, 3> Dpoint = boost::none) const {
352  return pose().range(point, Dcamera, Dpoint);
353  }
354 
360  double range(const Pose3& pose, OptionalJacobian<1, 6> Dcamera = boost::none,
361  OptionalJacobian<1, 6> Dpose = boost::none) const {
362  return this->pose().range(pose, Dcamera, Dpose);
363  }
364 
370  double range(const CalibratedCamera& camera, //
371  OptionalJacobian<1, 6> H1 = boost::none, //
372  OptionalJacobian<1, 6> H2 = boost::none) const {
373  return pose().range(camera.pose(), H1, H2);
374  }
375 
377 
378 private:
379 
382 
384  friend class boost::serialization::access;
385  template<class Archive>
386  void serialize(Archive & ar, const unsigned int /*version*/) {
387  ar
388  & boost::serialization::make_nvp("PinholeBase",
389  boost::serialization::base_object<PinholeBase>(*this));
390  }
391 
393 };
394 
395 // manifold traits
396 template <>
397 struct traits<CalibratedCamera> : public internal::Manifold<CalibratedCamera> {};
398 
399 template <>
400 struct traits<const CalibratedCamera> : public internal::Manifold<CalibratedCamera> {};
401 
402 // range traits, used in RangeFactor
403 template <typename T>
404 struct Range<CalibratedCamera, T> : HasRange<CalibratedCamera, T, double> {};
405 
406 } // namespace gtsam
407 
CalibratedCamera()
default constructor
Definition: CalibratedCamera.h:252
const Rot3 & rotation(OptionalJacobian< 3, 6 > H=boost::none) const
get rotation
Definition: Pose3.cpp:272
Point2_ project(const Point3_ &p_cam)
Expression version of PinholeBase::Project.
Definition: expressions.h:57
Definition: CalibratedCamera.h:240
3D Pose
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
Definition: BearingRange.h:38
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
Base exception type that uses tbb_exception if GTSAM is compiled with TBB.
Definition: ThreadsafeException.h:39
Definition: CalibratedCamera.h:45
static size_t Dim()
Definition: CalibratedCamera.h:324
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Definition: CalibratedCamera.h:32
Definition: Pose3.h:37
Definition: Point3.h:45
double range(const Point3 &point, OptionalJacobian< 1, 6 > Dcamera=boost::none, OptionalJacobian< 1, 3 > Dpoint=boost::none) const
Calculate range to a landmark.
Definition: CalibratedCamera.h:349
2D Point
Base class and basic functions for Manifold types.
Template to create a binary predicate.
Definition: Testable.h:110
double range(const CalibratedCamera &camera, OptionalJacobian< 1, 6 > H1=boost::none, OptionalJacobian< 1, 6 > H2=boost::none) const
Calculate range to another camera.
Definition: CalibratedCamera.h:370
Definition: Pose2.h:36
Both ManifoldTraits and Testable.
Definition: Manifold.h:120
Definition: Point2.h:40
size_t dim() const
Definition: CalibratedCamera.h:319
const Point3 & translation() const
get translation
Definition: CalibratedCamera.h:156
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
static std::pair< size_t, size_t > translationInterval()
Return the start and end indices (inclusive) of the translation component of the exponential map para...
Definition: CalibratedCamera.h:215
CalibratedCamera(const Pose3 &pose)
construct with pose
Definition: CalibratedCamera.h:256
Definition: Rot3.h:56
const Rot3 & rotation() const
get rotation
Definition: CalibratedCamera.h:151
PinholeBase()
default constructor
Definition: CalibratedCamera.h:115
Bearing-Range product.
double range(const Pose3 &pose, OptionalJacobian< 1, 6 > Dcamera=boost::none, OptionalJacobian< 1, 6 > Dpose=boost::none) const
Calculate range to another pose.
Definition: CalibratedCamera.h:360
static Pose3 Expmap(const Vector6 &xi, OptionalJacobian< 6, 6 > H=boost::none)
Exponential map at identity - create a rotation from canonical coordinates .
Definition: Pose3.cpp:120
Point3 backproject(const Point2 &pn, double depth) const
backproject a 2-dimensional point to a 3-dimensional point at given depth
Definition: CalibratedCamera.h:340
Definition: BearingRange.h:123
CalibratedCamera(const Vector &v)
construct from vector
Definition: CalibratedCamera.h:296
Point3 transform_from(const Point3 &p, OptionalJacobian< 3, 6 > Dpose=boost::none, OptionalJacobian< 3, 3 > Dpoint=boost::none) const
takes point in Pose coordinates and transforms it to world coordinates
Definition: Pose3.cpp:303
const Point3 & translation(OptionalJacobian< 3, 6 > H=boost::none) const
get translation
Definition: Pose3.cpp:265
PinholeBase(const Pose3 &pose)
constructor with pose
Definition: CalibratedCamera.h:119
Rot3 Rotation
Pose Concept requirements.
Definition: CalibratedCamera.h:50
double range(const Point3 &point, OptionalJacobian< 1, 6 > H1=boost::none, OptionalJacobian< 1, 3 > H2=boost::none) const
Calculate range to a landmark.
Definition: Pose3.cpp:339
Point2 Measurement
Some classes template on either PinholeCamera or StereoCamera, and this typedef informs those classes...
Definition: CalibratedCamera.h:57
const Pose3 & pose() const
return pose, constant version
Definition: CalibratedCamera.h:146
virtual ~CalibratedCamera()
destructor
Definition: CalibratedCamera.h:305
Global functions in a separate testing namespace.
Definition: chartTesting.h:28