gtsam
Loading...
Searching...
No Matches
PlanarProjectionFactor.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
26#pragma once
27
28#include <gtsam/base/Lie.h>
29#include <gtsam/base/Testable.h>
35#include <gtsam/geometry/Rot3.h>
38
39namespace gtsam {
40
45 class PlanarProjectionFactorBase {
46 protected:
47 PlanarProjectionFactorBase() {}
48
52 PlanarProjectionFactorBase(const Point2& measured) : measured_(measured) {}
53
67 const Point3& landmark,
68 const Pose2& wTb,
69 const Pose3& bTc,
70 const Cal3DS2& calib,
71 OptionalJacobian<2, 3> Hlandmark = {}, // (x, y, z)
72 OptionalJacobian<2, 3> HwTb = {}, // (x, y, theta)
73 OptionalJacobian<2, 6> HbTc = {}, // (rx, ry, rz, x, y, theta)
74 OptionalJacobian<2, 9> Hcalib = {}
75 ) const {
76#ifndef GTSAM_THROW_CHEIRALITY_EXCEPTION
77 try {
78#endif
79 Matrix63 Hp; // 6x3
80 Matrix66 H0; // 6x6
81 Pose3 wTc = Pose3::FromPose2(wTb, HwTb ? &Hp : nullptr).compose(bTc, HwTb ? &H0 : nullptr);
82 PinholeCamera<Cal3DS2> camera = PinholeCamera<Cal3DS2>(wTc, calib);
83 if (HwTb || HbTc) {
84 // Dpose is for pose3 (R,t)
85 Matrix26 Dpose;
86 Point2 result = camera.project(landmark, Dpose, Hlandmark, Hcalib);
87 if (HbTc)
88 *HbTc = Dpose;
89 if (HwTb)
90 *HwTb = Dpose * H0 * Hp;
91 return result;
92 } else {
93 return camera.project(landmark, {}, {}, {});
94 }
95#ifndef GTSAM_THROW_CHEIRALITY_EXCEPTION
96 } catch (CheiralityException& e) {
97 std::cout << "****** CHIRALITY EXCEPTION ******\n";
98 if (Hlandmark) Hlandmark->setZero();
99 if (HwTb) HwTb->setZero();
100 if (HbTc) HbTc->setZero();
101 if (Hcalib) Hcalib->setZero();
102 // return a large error
103 return Matrix::Constant(2, 1, 2.0 * calib.fx());
104 }
105#endif
106 }
107
108 Point2 measured_; // pixel measurement
109 };
110
111
118 class PlanarProjectionFactor1
119 : public PlanarProjectionFactorBase, public NoiseModelFactorN<Pose2> {
120 public:
121 typedef NoiseModelFactorN<Pose2> Base;
123 PlanarProjectionFactor1() {}
124
125 ~PlanarProjectionFactor1() override {}
126
128 NonlinearFactor::shared_ptr clone() const override {
129 return std::static_pointer_cast<NonlinearFactor>(
130 NonlinearFactor::shared_ptr(new PlanarProjectionFactor1(*this)));
131 }
132
133
144 Key poseKey,
145 const Point3& landmark,
146 const Point2& measured,
147 const Pose3& bTc,
148 const Cal3DS2& calib,
149 const SharedNoiseModel& model = {})
150 : PlanarProjectionFactorBase(measured),
151 NoiseModelFactorN<Pose2>(model, poseKey),
152 landmark_(landmark),
153 bTc_(bTc),
154 calib_(calib) {}
155
160 Vector evaluateError(const Pose2& wTb, OptionalMatrixType HwTb) const override {
161 return predict(landmark_, wTb, bTc_, calib_, {}, HwTb, {}, {}) - measured_;
162 }
163
164 private:
165 Point3 landmark_; // landmark
166 Pose3 bTc_; // "body to camera": camera offset to robot pose
167 Cal3DS2 calib_; // camera calibration
168 };
169
170 template<>
172 public Testable<PlanarProjectionFactor1> {};
173
180 class PlanarProjectionFactor2
181 : public PlanarProjectionFactorBase,
182 public NoiseModelFactorT<Vector2, Pose2, Point3> {
183 public:
186
187 PlanarProjectionFactor2() {}
188
189 ~PlanarProjectionFactor2() override {}
190
192 NonlinearFactor::shared_ptr clone() const override {
193 return std::static_pointer_cast<NonlinearFactor>(
194 NonlinearFactor::shared_ptr(new PlanarProjectionFactor2(*this)));
195 }
196
207 Key poseKey,
208 Key landmarkKey,
209 const Point2& measured,
210 const Pose3& bTc,
211 const Cal3DS2& calib,
212 const SharedNoiseModel& model = {})
213 : PlanarProjectionFactorBase(measured),
214 Base(model, poseKey, landmarkKey),
215 bTc_(bTc),
216 calib_(calib) {}
217
225 const Pose2& wTb,
226 const Point3& landmark,
228 OptionalMatrixType Hlandmark) const override {
229 return predict(landmark, wTb, bTc_, calib_, Hlandmark, HwTb, {}, {}) - measured_;
230 }
231
232 private:
233 Pose3 bTc_; // "body to camera": camera offset to robot pose
234 Cal3DS2 calib_; // camera calibration
235 };
236
237 template<>
239 public Testable<PlanarProjectionFactor2> {};
240
247 class PlanarProjectionFactor3
248 : public PlanarProjectionFactorBase,
249 public NoiseModelFactorT<Vector2, Pose2, Pose3, Cal3DS2> {
250 public:
253
254 PlanarProjectionFactor3() {}
255
256 ~PlanarProjectionFactor3() override {}
257
259 NonlinearFactor::shared_ptr clone() const override {
260 return std::static_pointer_cast<NonlinearFactor>(
261 NonlinearFactor::shared_ptr(new PlanarProjectionFactor3(*this)));
262 }
263
273 PlanarProjectionFactor3(Key poseKey, Key offsetKey, Key calibKey,
274 const Point3& landmark, const Point2& measured,
275 const SharedNoiseModel& model = {})
276 : PlanarProjectionFactorBase(measured),
277 Base(model, poseKey, offsetKey, calibKey),
278 landmark_(landmark) {}
279
289 const Pose2& wTb,
290 const Pose3& bTc,
291 const Cal3DS2& calib,
294 OptionalMatrixType Hcalib) const override {
295 return predict(landmark_, wTb, bTc, calib, {}, HwTb, HbTc, Hcalib) - measured_;
296 }
297
298 private:
299 Point3 landmark_; // landmark
300 };
301
302 template<>
304 public Testable<PlanarProjectionFactor3> {};
305
306} // namespace gtsam
Concept check for values that can be used in unit tests.
Base class and basic functions for Lie types.
3D Point
Base class for all pinhole cameras.
3D Pose manifold SO(3) x R^3 and group SE(3)
2D Pose
Calibration of a camera with radial distortion, calculations in base class Cal3DS2_Base.
3D rotation represented as a rotation matrix or quaternion
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
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
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
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
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
double fx() const
focal length x
Definition Cal3.h:138
Calibration of a camera with radial distortion that also supports Lie-group behaviors for optimizatio...
Definition Cal3DS2.h:35
A 2D pose (Point2,Rot2).
Definition Pose2.h:39
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
static Pose3 FromPose2(const Pose2 &p, OptionalJacobian< 6, 3 > H={})
Construct from Pose2 in the xy plane, with derivative.
Definition Pose3.cpp:55
NoiseModelFactorT()
Definition NoiseModelFactorN.h:257
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Camera projection for robot on the floor.
Definition PlanarProjectionFactor.h:45
PlanarProjectionFactorBase(const Point2 &measured)
Definition PlanarProjectionFactor.h:52
Point2 predict(const Point3 &landmark, const Pose2 &wTb, const Pose3 &bTc, const Cal3DS2 &calib, OptionalJacobian< 2, 3 > Hlandmark={}, OptionalJacobian< 2, 3 > HwTb={}, OptionalJacobian< 2, 6 > HbTc={}, OptionalJacobian< 2, 9 > Hcalib={}) const
Predict the projection of the landmark in camera pixels.
Definition PlanarProjectionFactor.h:66
One variable: the pose.
Definition PlanarProjectionFactor.h:119
Vector evaluateError(const Pose2 &wTb, OptionalMatrixType HwTb) const override
Definition PlanarProjectionFactor.h:160
NonlinearFactor::shared_ptr clone() const override
Definition PlanarProjectionFactor.h:128
PlanarProjectionFactor1(Key poseKey, const Point3 &landmark, const Point2 &measured, const Pose3 &bTc, const Cal3DS2 &calib, const SharedNoiseModel &model={})
constructor for known landmark, offset, and calibration
Definition PlanarProjectionFactor.h:143
Two unknowns: the pose and the landmark.
Definition PlanarProjectionFactor.h:182
NonlinearFactor::shared_ptr clone() const override
Definition PlanarProjectionFactor.h:192
PlanarProjectionFactor2(Key poseKey, Key landmarkKey, const Point2 &measured, const Pose3 &bTc, const Cal3DS2 &calib, const SharedNoiseModel &model={})
constructor for variable landmark, known offset and calibration
Definition PlanarProjectionFactor.h:206
Vector2 evaluateError(const Pose2 &wTb, const Point3 &landmark, OptionalMatrixType HwTb, OptionalMatrixType Hlandmark) const override
Definition PlanarProjectionFactor.h:224
Three unknowns: the pose, the camera offset, and the camera calibration.
Definition PlanarProjectionFactor.h:249
NonlinearFactor::shared_ptr clone() const override
Definition PlanarProjectionFactor.h:259
PlanarProjectionFactor3(Key poseKey, Key offsetKey, Key calibKey, const Point3 &landmark, const Point2 &measured, const SharedNoiseModel &model={})
constructor for variable pose, offset, and calibration, known landmark.
Definition PlanarProjectionFactor.h:273
Vector2 evaluateError(const Pose2 &wTb, const Pose3 &bTc, const Cal3DS2 &calib, OptionalMatrixType HwTb, OptionalMatrixType HbTc, OptionalMatrixType Hcalib) const override
Definition PlanarProjectionFactor.h:288