gtsam
Loading...
Searching...
No Matches
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
18
19#pragma once
20
21#include <gtsam/base/Manifold.h>
24#include <gtsam/base/concepts.h>
25#include <gtsam/dllexport.h>
29#if GTSAM_ENABLE_BOOST_SERIALIZATION
30#include <boost/serialization/nvp.hpp>
31#endif
32
33namespace gtsam {
34
35class GTSAM_EXPORT CheiralityException: public ThreadsafeException<CheiralityException> {
36public:
37 CheiralityException()
38 : CheiralityException(std::numeric_limits<Key>::max()) {}
39
40 CheiralityException(Key j)
41 : ThreadsafeException<CheiralityException>("CheiralityException"),
42 j_(j) {}
43
44 Key nearbyVariable() const {return j_;}
45
46private:
47 Key j_;
48};
49
55class GTSAM_EXPORT PinholeBase {
56
57public:
58
60 using Rotation = Rot3;
61 using Translation = Point3;
62
68 using MeasurementVector = Point2Vector;
69
70private:
71
72 Pose3 pose_;
73
74protected:
75
78
84 static Matrix26 Dpose(const Point2& pn, double d);
85
92 static Matrix23 Dpoint(const Point2& pn, double d, const Matrix3& Rt);
93
95
96public:
97
100
108 static Pose3 LevelPose(const Pose2& pose2, double height);
109
118 static Pose3 LookatPose(const Point3& eye, const Point3& target,
119 const Point3& upVector);
120
124
127
129 explicit PinholeBase(const Pose3& pose) : pose_(pose) {}
130
134
135 explicit PinholeBase(const Vector& v) : pose_(Pose3::Expmap(v)) {}
136
138 virtual ~PinholeBase() = default;
139
143
145 bool equals(const PinholeBase &camera, double tol = 1e-9) const;
146
148 virtual void print(const std::string& s = "PinholeBase") const;
149
153
155 const Pose3& pose() const {
156 return pose_;
157 }
158
160 const Rot3& rotation() const {
161 return pose_.rotation();
162 }
163
165 const Point3& translation() const {
166 return pose_.translation();
167 }
168
170 const Pose3& getPose(OptionalJacobian<6, 6> H) const;
171
175
181 static Point2 Project(const Point3& pc, //
182 OptionalJacobian<2, 3> Dpoint = {});
183
189 static Point2 Project(const Unit3& pc, //
190 OptionalJacobian<2, 2> Dpoint = {});
191
193 std::pair<Point2, bool> projectSafe(const Point3& pw) const;
194
200 Point2 project2(const Point3& point, OptionalJacobian<2, 6> Dpose =
201 {}, OptionalJacobian<2, 3> Dpoint = {}) const;
202
208 Point2 project2(const Unit3& point,
209 OptionalJacobian<2, 6> Dpose = {},
210 OptionalJacobian<2, 2> Dpoint = {}) const;
211
213 static Point3 BackprojectFromCamera(const Point2& p, const double depth,
214 OptionalJacobian<3, 2> Dpoint = {},
215 OptionalJacobian<3, 1> Ddepth = {});
216
220
226 static std::pair<size_t, size_t> TranslationInterval() {
227 return {3, 5};
228 }
229
231
232private:
233
234#if GTSAM_ENABLE_BOOST_SERIALIZATION
236 friend class boost::serialization::access;
237 template<class Archive>
238 void serialize(Archive & ar, const unsigned int /*version*/) {
239 ar & BOOST_SERIALIZATION_NVP(pose_);
240 }
241#endif
242};
243// end of class PinholeBase
244
252class GTSAM_EXPORT CalibratedCamera: public PinholeBase {
253
254public:
255
256 inline constexpr static auto dimension = 6;
257
259 bool equals(const CalibratedCamera& camera, double tol = 1e-9) const {
260 return PinholeBase::equals(camera, tol);
261 }
262
265
269
271 explicit CalibratedCamera(const Pose3& pose) :
273 }
274
278
279 // Create CalibratedCamera, with derivatives
280 static CalibratedCamera Create(const Pose3& pose,
282 if (H1) *H1 = I_6x6;
283 return CalibratedCamera(pose);
284 }
285
292 static CalibratedCamera Level(const Pose2& pose2, double height);
293
302 static CalibratedCamera Lookat(const Point3& eye, const Point3& target,
303 const Point3& upVector);
304
308
310 explicit CalibratedCamera(const Vector &v) :
311 PinholeBase(v) {
312 }
313
317
319 CalibratedCamera retract(const Vector& d) const;
320
322 Vector localCoordinates(const CalibratedCamera& T2) const;
323
325 void print(const std::string& s = "CalibratedCamera") const override {
327 }
328
329 inline size_t dim() const {
330 return dimension;
331 }
332
333 inline static size_t Dim() {
334 return dimension;
335 }
336
340
345 Point2 project(const Point3& point, OptionalJacobian<2, 6> Dcamera =
346 {}, OptionalJacobian<2, 3> Dpoint = {}) const;
347
349 Point3 backproject(const Point2& pn, double depth,
350 OptionalJacobian<3, 6> Dresult_dpose = {},
351 OptionalJacobian<3, 2> Dresult_dp = {},
352 OptionalJacobian<3, 1> Dresult_ddepth = {}) const {
353
354 Matrix32 Dpoint_dpn;
355 Matrix31 Dpoint_ddepth;
356 const Point3 point = BackprojectFromCamera(pn, depth,
357 Dresult_dp ? &Dpoint_dpn : 0,
358 Dresult_ddepth ? &Dpoint_ddepth : 0);
359
360 Matrix33 Dresult_dpoint;
361 const Point3 result = pose().transformFrom(point, Dresult_dpose,
362 (Dresult_ddepth ||
363 Dresult_dp) ? &Dresult_dpoint : 0);
364
365 if (Dresult_dp)
366 *Dresult_dp = Dresult_dpoint * Dpoint_dpn;
367 if (Dresult_ddepth)
368 *Dresult_ddepth = Dresult_dpoint * Dpoint_ddepth;
369
370 return result;
371 }
372
378 double range(const Point3& point,
379 OptionalJacobian<1, 6> Dcamera = {},
380 OptionalJacobian<1, 3> Dpoint = {}) const {
381 return pose().range(point, Dcamera, Dpoint);
382 }
383
389 double range(const Pose3& pose, OptionalJacobian<1, 6> Dcamera = {},
390 OptionalJacobian<1, 6> Dpose = {}) const {
391 return this->pose().range(pose, Dcamera, Dpose);
392 }
393
399 double range(const CalibratedCamera& camera, //
400 OptionalJacobian<1, 6> H1 = {}, //
401 OptionalJacobian<1, 6> H2 = {}) const {
402 return pose().range(camera.pose(), H1, H2);
403 }
404
406
407private:
408
411
412#if GTSAM_ENABLE_BOOST_SERIALIZATION
414 friend class boost::serialization::access;
415 template<class Archive>
416 void serialize(Archive & ar, const unsigned int /*version*/) {
417 ar
418 & boost::serialization::make_nvp("PinholeBase",
419 boost::serialization::base_object<PinholeBase>(*this));
420 }
421#endif
422
424};
425
426// manifold traits
427template <>
428struct traits<CalibratedCamera> : public internal::Manifold<CalibratedCamera> {};
429
430template <>
431struct traits<const CalibratedCamera> : public internal::Manifold<CalibratedCamera> {};
432
433// range traits, used in RangeFactor
434template <typename T>
435struct Range<CalibratedCamera, T> : HasRange<CalibratedCamera, T, double> {};
436
437} // namespace gtsam
Macros for Matrix constants to avoid excessive template instantiation.
Base exception type that uses tbb_allocator if GTSAM is compiled with TBB.
Base class and basic functions for Manifold types.
3D Pose manifold SO(3) x R^3 and group SE(3)
2D Point
Bearing-Range product.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
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_ project(const Point3_ &p_cam)
Expression version of PinholeBase::Project.
Definition expressions.h:134
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
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
ThreadsafeException()
Definition ThreadsafeException.h:61
Definition BearingRange.h:42
Definition BearingRange.h:196
A pinhole camera class that has a Pose3, functions as base class for all pinhole cameras.
Definition CalibratedCamera.h:55
Point2 Measurement
Some classes template on either PinholeCamera or StereoCamera, and this typedef informs those classes...
Definition CalibratedCamera.h:67
PinholeBase()
Default constructor.
Definition CalibratedCamera.h:126
static Matrix26 Dpose(const Point2 &pn, double d)
Calculate Jacobian with respect to pose.
Definition CalibratedCamera.cpp:28
virtual void print(const std::string &s="PinholeBase") const
print
Definition CalibratedCamera.cpp:75
PinholeBase(const Pose3 &pose)
Constructor with pose.
Definition CalibratedCamera.h:129
const Point3 & translation() const
get translation
Definition CalibratedCamera.h:165
Rot3 Rotation
Pose Concept requirements.
Definition CalibratedCamera.h:60
const Rot3 & rotation() const
get rotation
Definition CalibratedCamera.h:160
const Pose3 & pose() const
return pose, constant version
Definition CalibratedCamera.h:155
static Pose3 LevelPose(const Pose2 &pose2, double height)
Create a level pose at the given 2D pose and height.
Definition CalibratedCamera.cpp:50
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:226
bool equals(const PinholeBase &camera, double tol=1e-9) const
assert equality up to a tolerance
Definition CalibratedCamera.cpp:70
static Matrix23 Dpoint(const Point2 &pn, double d, const Matrix3 &Rt)
Calculate Jacobian with respect to point.
Definition CalibratedCamera.cpp:38
static Pose3 LookatPose(const Point3 &eye, const Point3 &target, const Point3 &upVector)
Create a camera pose at the given eye position looking at a target point in the scene with the specif...
Definition CalibratedCamera.cpp:59
virtual ~PinholeBase()=default
Default destructor.
A Calibrated camera class [R|-R't], calibration K=I.
Definition CalibratedCamera.h:252
bool equals(const CalibratedCamera &camera, double tol=1e-9) const
Compare with another calibrated camera.
Definition CalibratedCamera.h:259
CalibratedCamera()
default constructor
Definition CalibratedCamera.h:267
CalibratedCamera(const Vector &v)
construct from vector
Definition CalibratedCamera.h:310
double range(const Point3 &point, OptionalJacobian< 1, 6 > Dcamera={}, OptionalJacobian< 1, 3 > Dpoint={}) const
Calculate range to a landmark.
Definition CalibratedCamera.h:378
Point3 backproject(const Point2 &pn, double depth, OptionalJacobian< 3, 6 > Dresult_dpose={}, OptionalJacobian< 3, 2 > Dresult_dp={}, OptionalJacobian< 3, 1 > Dresult_ddepth={}) const
backproject a 2-dimensional point to a 3-dimensional point at given depth
Definition CalibratedCamera.h:349
double range(const Pose3 &pose, OptionalJacobian< 1, 6 > Dcamera={}, OptionalJacobian< 1, 6 > Dpose={}) const
Calculate range to another pose.
Definition CalibratedCamera.h:389
void print(const std::string &s="CalibratedCamera") const override
print
Definition CalibratedCamera.h:325
CalibratedCamera(const Pose3 &pose)
construct with pose
Definition CalibratedCamera.h:271
double range(const CalibratedCamera &camera, OptionalJacobian< 1, 6 > H1={}, OptionalJacobian< 1, 6 > H2={}) const
Calculate range to another camera.
Definition CalibratedCamera.h:399
A 2D pose (Point2,Rot2).
Definition Pose2.h:39
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Point3 transformFrom(const Point3 &point, OptionalJacobian< 3, 6 > Hself={}, OptionalJacobian< 3, 3 > Hpoint={}) const
takes point in Pose coordinates and transforms it to world coordinates
Definition Pose3.cpp:180
double range(const Point3 &point, OptionalJacobian< 1, 6 > Hself={}, OptionalJacobian< 1, 3 > Hpoint={}) const
Calculate range to a landmark.
Definition Pose3.cpp:232
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65