10#include <gtsam/geometry/EssentialMatrix.h>
52 template <
class CALIBRATION>
55 boost::shared_ptr<CALIBRATION> K)
63 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
64 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
65 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
70 const std::string& s =
"",
71 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
73 std::cout <<
" EssentialMatrixFactor with measurements\n ("
74 << vA_.transpose() <<
")' and (" << vB_.transpose() <<
")'"
81 boost::optional<Matrix&> H = boost::none)
const override {
83 error << E.error(vA_, vB_, H);
130 template <
class CALIBRATION>
133 boost::shared_ptr<CALIBRATION> K)
136 pn_(K->calibrate(pB)) {
137 f_ = 0.5 * (K->fx() + K->fy());
141 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
142 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
143 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
148 const std::string& s =
"",
149 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
151 std::cout <<
" EssentialMatrixFactor2 with measurements\n ("
152 << dP1_.transpose() <<
")' and (" << pn_.transpose() <<
")'"
163 boost::optional<Matrix&> DE = boost::none,
164 boost::optional<Matrix&> Dd = boost::none)
const override {
177 Point3 _1T2 = E.direction().point3();
179 Point3 dP2 = E.rotation().unrotate(dP1_ - d1T2);
185 Matrix D_1T2_dir, DdP2_rot, DP2_point;
187 Point3 _1T2 = E.direction().point3(D_1T2_dir);
189 Point3 dP2 = E.rotation().unrotate(dP1_ - d1T2, DdP2_rot, DP2_point);
196 DdP2_E << DdP2_rot, -DP2_point * d * D_1T2_dir;
197 *DE = f_ * Dpn_dP2 * DdP2_E;
202 *Dd = -f_ * (Dpn_dP2 * (DP2_point * _1T2));
204 Point2 reprojectionError = pn - pn_;
205 return f_ * reprojectionError;
247 template <
class CALIBRATION>
250 boost::shared_ptr<CALIBRATION> K)
254 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
255 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
256 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
261 const std::string& s =
"",
262 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
264 std::cout <<
" EssentialMatrixFactor3 with rotation " << cRb_ << std::endl;
274 boost::optional<Matrix&> DE = boost::none,
275 boost::optional<Matrix&> Dd = boost::none)
const override {
283 Matrix D_e_cameraE, D_cameraE_E;
286 *DE = D_e_cameraE * D_cameraE_E;
309template <
class CALIBRATION>
319 typedef Eigen::Matrix<double, 2, DimK> JacobianCalibration;
333 :
Base(model, keyE, keyK), pA_(pA), pB_(pB) {}
336 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
337 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
338 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
343 const std::string& s =
"",
344 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
346 std::cout <<
" EssentialMatrixFactor4 with measurements\n ("
347 << pA_.transpose() <<
")' and (" << pB_.transpose() <<
")'"
362 boost::optional<Matrix&> H1 = boost::none,
363 boost::optional<Matrix&> H2 = boost::none)
const override {
365 JacobianCalibration cA_H_K;
366 JacobianCalibration cB_H_K;
367 Point2 cA = K.calibrate(pA_, H2 ? &cA_H_K : 0, boost::none);
368 Point2 cB = K.calibrate(pB_, H2 ? &cB_H_K : 0, boost::none);
381 *H2 = vB.transpose() * E.matrix().transpose().leftCols<2>() * cA_H_K +
382 vA.transpose() * E.matrix().leftCols<2>() * cB_H_K;
386 error << E.error(vA, vB, H1);
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW
This marks a GTSAM object to require alignment.
Definition: types.h:277
Base class for all pinhole cameras.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
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:27
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:35
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:736
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
Give fixed size dimension of a type, fails at compile time if dynamic.
Definition: Manifold.h:164
static Point2 Project(const Point3 &pc, OptionalJacobian< 2, 3 > Dpoint=boost::none)
Project from 3D point in camera coordinates into image Does not throw a CheiralityException,...
Definition: CalibratedCamera.cpp:88
An essential matrix is like a Pose3, except with translation up to scale It is named after the 3*3 ma...
Definition: EssentialMatrix.h:26
static Vector3 Homogeneous(const Point2 &p)
Static function to convert Point2 to homogeneous coordinates.
Definition: EssentialMatrix.h:34
This is the base class for all factor types.
Definition: Factor.h:56
double error(const Values &c) const override
Calculate the error of the factor.
Definition: NonlinearFactor.cpp:127
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Print.
Definition: NonlinearFactor.cpp:63
A convenient base class for creating your own NoiseModelFactor with 1 variable.
Definition: NonlinearFactor.h:285
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:369
Key key1() const
methods to retrieve both keys
Definition: NonlinearFactor.h:401
Factor that evaluates epipolar error p'Ep for given essential matrix.
Definition: EssentialMatrixFactor.h:21
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: EssentialMatrixFactor.h:63
EssentialMatrixFactor(Key key, const Point2 &pA, const Point2 &pB, const SharedNoiseModel &model)
Constructor.
Definition: EssentialMatrixFactor.h:36
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: EssentialMatrixFactor.h:69
EssentialMatrixFactor(Key key, const Point2 &pA, const Point2 &pB, const SharedNoiseModel &model, boost::shared_ptr< CALIBRATION > K)
Constructor.
Definition: EssentialMatrixFactor.h:53
Vector evaluateError(const EssentialMatrix &E, boost::optional< Matrix & > H=boost::none) const override
vector of errors returns 1D vector
Definition: EssentialMatrixFactor.h:79
Binary factor that optimizes for E and inverse depth d: assumes measurement in image 2 is perfect,...
Definition: EssentialMatrixFactor.h:96
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: EssentialMatrixFactor.h:141
Vector evaluateError(const EssentialMatrix &E, const double &d, boost::optional< Matrix & > DE=boost::none, boost::optional< Matrix & > Dd=boost::none) const override
Override this method to finish implementing a binary factor.
Definition: EssentialMatrixFactor.h:161
EssentialMatrixFactor2(Key key1, Key key2, const Point2 &pA, const Point2 &pB, const SharedNoiseModel &model, boost::shared_ptr< CALIBRATION > K)
Constructor.
Definition: EssentialMatrixFactor.h:131
EssentialMatrixFactor2(Key key1, Key key2, const Point2 &pA, const Point2 &pB, const SharedNoiseModel &model)
Constructor.
Definition: EssentialMatrixFactor.h:113
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: EssentialMatrixFactor.h:147
Binary factor that optimizes for E and inverse depth d: assumes measurement in image 2 is perfect,...
Definition: EssentialMatrixFactor.h:218
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: EssentialMatrixFactor.h:260
EssentialMatrixFactor3(Key key1, Key key2, const Point2 &pA, const Point2 &pB, const Rot3 &cRb, const SharedNoiseModel &model)
Constructor.
Definition: EssentialMatrixFactor.h:234
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: EssentialMatrixFactor.h:254
Vector evaluateError(const EssentialMatrix &E, const double &d, boost::optional< Matrix & > DE=boost::none, boost::optional< Matrix & > Dd=boost::none) const override
Override this method to finish implementing a binary factor.
Definition: EssentialMatrixFactor.h:272
EssentialMatrixFactor3(Key key1, Key key2, const Point2 &pA, const Point2 &pB, const Rot3 &cRb, const SharedNoiseModel &model, boost::shared_ptr< CALIBRATION > K)
Constructor.
Definition: EssentialMatrixFactor.h:248
Binary factor that optimizes for E and calibration K using the algebraic epipolar error (K^-1 pA)'E (...
Definition: EssentialMatrixFactor.h:311
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: EssentialMatrixFactor.h:342
Vector evaluateError(const EssentialMatrix &E, const CALIBRATION &K, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Calculate the algebraic epipolar error pA' (K^-1)' E K pB.
Definition: EssentialMatrixFactor.h:360
EssentialMatrixFactor4(Key keyE, Key keyK, const Point2 &pA, const Point2 &pB, const SharedNoiseModel &model)
Constructor.
Definition: EssentialMatrixFactor.h:331
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: EssentialMatrixFactor.h:336