31 template<
class POSE,
class LANDMARK>
37 Cal3_S2Stereo::shared_ptr K_;
38 std::optional<POSE> body_P_sensor_;
41 bool throwCheirality_;
42 bool verboseCheirality_;
59 throwCheirality_(false), verboseCheirality_(false) {}
71 Key poseKey,
Key landmarkKey,
const Cal3_S2Stereo::shared_ptr& K,
72 std::optional<POSE> body_P_sensor = {}) :
73 Base(model, poseKey, landmarkKey), measured_(measured), K_(K), body_P_sensor_(body_P_sensor),
74 throwCheirality_(
false), verboseCheirality_(
false) {}
88 Key poseKey,
Key landmarkKey,
const Cal3_S2Stereo::shared_ptr& K,
90 std::optional<POSE> body_P_sensor = {}) :
91 Base(model, poseKey, landmarkKey), measured_(measured), K_(K), body_P_sensor_(body_P_sensor),
92 throwCheirality_(throwCheirality), verboseCheirality_(verboseCheirality) {}
98 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
100 gtsam::NonlinearFactor::shared_ptr(
new This(*
this))); }
107 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
109 measured_.
print(s +
".z");
110 if(this->body_P_sensor_)
111 this->body_P_sensor_->print(
" sensor pose in body frame: ");
121 && measured_.
equals(e->measured_, tol)
122 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_)));
132 StereoCamera stereoCam(pose.compose(*body_P_sensor_, H0), K_);
133 StereoPoint2 reprojectionError(stereoCam.project(point, H1, H2) - measured_);
135 return reprojectionError.
vector();
137 StereoCamera stereoCam(pose.compose(*body_P_sensor_), K_);
138 return (stereoCam.project(point, H1, H2) - measured_).vector();
142 return (stereoCam.
project(point, H1, H2) - measured_).vector();
145 if (H1) *H1 = Matrix::Zero(3,6);
147 if (verboseCheirality_)
148 std::cout << e.what() <<
": Landmark "<< DefaultKeyFormatter(this->key2()) <<
149 " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
150 if (throwCheirality_)
153 return Vector3::Constant(2.0 * K_->fx());
173 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 175 friend class boost::serialization::access;
176 template<
class Archive>
177 void serialize(Archive & ar,
const unsigned int ) {
179 ar & boost::serialization::make_nvp(
"NoiseModelFactor2",
180 boost::serialization::base_object<Base>(*
this));
181 ar & BOOST_SERIALIZATION_NVP(measured_);
182 ar & BOOST_SERIALIZATION_NVP(K_);
183 ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
184 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
185 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
191 template<
class T1,
class T2>
Definition: StereoCamera.h:26
const Cal3_S2Stereo::shared_ptr calibration() const
Definition: StereoFactor.h:162
Definition: NonlinearFactor.h:431
bool verboseCheirality() const
Definition: StereoFactor.h:167
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
~GenericStereoFactor() override
Definition: StereoFactor.h:95
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
Definition: Testable.h:152
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Definition: NonlinearFactor.h:68
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: StereoFactor.h:107
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
void print(const std::string &s="") const
The most common 5DOF 3D->2D calibration, stereo version.
Definition: Cal3_S2Stereo.h:30
Vector3 vector() const
Definition: StereoPoint2.h:117
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: StereoFactor.h:98
const StereoPoint2 & measured() const
Definition: StereoFactor.h:157
StereoPoint2 project(const Point3 &point) const
Project 3D point to StereoPoint2 (uL,uR,v)
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
GenericStereoFactor()
Definition: StereoFactor.h:58
Definition: chartTesting.h:28
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Definition: StereoFactor.h:117
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: StereoPoint2.h:34
bool throwCheirality() const
Definition: StereoFactor.h:170
Definition: StereoFactor.h:32
GenericStereoFactor(const StereoPoint2 &measured, const SharedNoiseModel &model, Key poseKey, Key landmarkKey, const Cal3_S2Stereo::shared_ptr &K, bool throwCheirality, bool verboseCheirality, std::optional< POSE > body_P_sensor={})
Definition: StereoFactor.h:87
A Rectified Stereo Camera.
Non-linear factor base classes.
NoiseModelFactorN< POSE, LANDMARK > Base
typedef for base class
Definition: StereoFactor.h:47
GenericStereoFactor(const StereoPoint2 &measured, const SharedNoiseModel &model, Key poseKey, Key landmarkKey, const Cal3_S2Stereo::shared_ptr &K, std::optional< POSE > body_P_sensor={})
Definition: StereoFactor.h:70
std::shared_ptr< GenericStereoFactor > shared_ptr
typedef for shared pointer to this object
Definition: StereoFactor.h:49
Vector3 Point3
Definition: Point3.h:38
Definition: StereoCamera.h:47
GenericStereoFactor< POSE, LANDMARK > This
typedef for this class (with templates)
Definition: StereoFactor.h:48
POSE CamPose
typedef for Pose Lie Value type
Definition: StereoFactor.h:50
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
Vector evaluateError(const Pose3 &pose, const Point3 &point, OptionalMatrixType H1, OptionalMatrixType H2) const override
Definition: StereoFactor.h:126
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
bool equals(const StereoPoint2 &q, double tol=1e-9) const
Definition: StereoPoint2.h:66