33 #include <boost/optional.hpp> 34 #include <boost/make_shared.hpp> 61 const SmartStereoProjectionParams
params_;
73 typedef boost::shared_ptr<SmartStereoProjectionFactor>
shared_ptr;
106 std::cout <<
s <<
"SmartStereoProjectionFactor\n";
108 std::cout <<
"triangulationParameters:\n" << params_.
triangulation << std::endl;
109 std::cout <<
"result:\n" << result_ << std::endl;
127 size_t m = cameras.size();
129 bool retriangulate =
false;
132 if (cameraPosesTriangulation_.empty()
133 || cameras.size() != cameraPosesTriangulation_.size())
134 retriangulate =
true;
136 if (!retriangulate) {
137 for (
size_t i = 0;
i < cameras.size();
i++) {
138 if (!cameras[
i].
pose().equals(cameraPosesTriangulation_[
i],
140 retriangulate =
true;
147 cameraPosesTriangulation_.clear();
148 cameraPosesTriangulation_.reserve(m);
149 for (
size_t i = 0;
i <
m;
i++)
151 cameraPosesTriangulation_.push_back(cameras[
i].pose());
154 return retriangulate;
165 size_t m = cameras.size();
169 MonoCameras monoCameras;
170 MonoMeasurements monoMeasured;
171 for(
size_t i = 0;
i <
m;
i++) {
172 const Pose3 leftPose = cameras[
i].pose();
173 const Cal3_S2 monoCal = cameras[
i].calibration().calibration();
174 const MonoCamera leftCamera_i(leftPose,monoCal);
176 const Pose3 rightPose = leftPose.
compose( left_Pose_right );
177 const MonoCamera rightCamera_i(rightPose,monoCal);
179 monoCameras.push_back(leftCamera_i);
180 monoMeasured.push_back(
Point2(zi.
uL(),zi.
v()));
182 monoCameras.push_back(rightCamera_i);
183 monoMeasured.push_back(
Point2(zi.
uR(),zi.
v()));
195 return bool(result_);
200 const Cameras&
cameras,
const double lambda = 0.0,
bool diagonalDamping =
203 size_t numKeys = this->
keys_.size();
206 std::vector<Matrix> Gs(numKeys * (numKeys + 1) / 2);
207 std::vector<Vector> gs(numKeys);
209 if (this->
measured_.size() != cameras.size())
210 throw std::runtime_error(
"SmartStereoProjectionHessianFactor: this->" 211 "measured_.size() inconsistent with input");
221 return boost::make_shared<RegularHessianFactor<Base::Dim> >(this->
keys_,
238 return boost::make_shared<RegularHessianFactor<Base::Dim> >(this->
keys_,
274 return boost::make_shared<JacobianFactorSVD<Base::Dim, ZDim> >(this->
keys_);
301 const double lambda = 0.0)
const {
313 throw std::runtime_error(
"SmartStereoFactorlinearize: unknown mode");
323 const double lambda = 0.0)
const {
342 cameras.
project2(*result_, boost::none, E);
343 return nonDegenerate;
362 const Cameras&
cameras)
const {
365 throw (
"computeJacobiansWithTriangulatedPoint");
386 return nonDegenerate;
397 return nonDegenerate;
407 return Vector::Zero(cameras.size() *
Base::ZDim);
417 boost::optional<Point3> externalPoint = boost::none)
const {
428 throw(std::runtime_error(
"Backproject at infinity not implemented for SmartStereo."));
442 if (this->
active(values)) {
453 boost::optional<typename Cameras::FBlocks&>
Fs = boost::none,
454 boost::optional<Matrix&>
E = boost::none)
const override 457 for(
size_t i=0;
i < cameras.size();
i++){
463 for(
size_t ii=0; ii<
Dim; ii++)
467 E->row(
ZDim *
i + 1) = Matrix::Zero(1,
E->cols());
470 ue(
ZDim *
i + 1) = 0.0;
505 template<
class ARCHIVE>
507 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
516 SmartStereoProjectionFactor> {
ZVector project2(const POINT &point, boost::optional< FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
MonoCamera::MeasurementVector MonoMeasurements
boost::shared_ptr< JacobianFactor > createJacobianSVDFactor(const Cameras &cameras, double lambda) const
different (faster) way to compute Jacobian factor
TriangulationResult point(const Values &values) const
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
bool triangulateAndComputeE(Matrix &E, const Values &values) const
PinholeCamera< Cal3_S2 > MonoCamera
Vector of monocular cameras (stereo treated as 2 monocular)
TriangulationResult triangulateSafe(const Cameras &cameras) const
triangulateSafe
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
bool behindCamera() const
bool decideIfTriangulate(const Cameras &cameras) const
Check if the new linearization point_ is the same as the one used for previous triangulation.
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
DegeneracyMode degeneracyMode
How to linearize the factor.
std::vector< Pose3 > cameraPosesTriangulation_
virtual Cameras cameras(const Values &values) const
Collect all cameras: important that in key order.
boost::shared_ptr< GaussianFactor > linearizeDamped(const Cameras &cameras, const double lambda=0.0) const
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
boost::shared_ptr< SmartStereoProjectionFactor > shared_ptr
shorthand for a smart pointer to a factor
TriangulationParameters triangulation
KeyVector keys_
The keys involved in this factor.
boost::shared_ptr< GaussianFactor > linearizeDamped(const Values &values, const double lambda=0.0) const
double totalReprojectionError(const Cameras &cameras, boost::optional< Point3 > externalPoint=boost::none) const
double error(const Values &values) const override
Calculate total reprojection error.
SmartFactorBase< StereoCamera > Base
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
A set of cameras, all with their own calibration.
static const KeyFormatter DefaultKeyFormatter
bool triangulateAndComputeJacobians(FBlocks &Fs, Matrix &E, Vector &b, const Values &values) const
Version that takes values, and creates the point.
boost::shared_ptr< RegularHessianFactor< Base::Dim > > createHessianFactor(const Cameras &cameras, const double lambda=0.0, bool diagonalDamping=false) const
linearize returns a Hessianfactor that is an approximation of error(p)
virtual bool active(const Values &) const
bool triangulateForLinearize(const Cameras &cameras) const
triangulate
Base class to create smart factors on poses or cameras.
bool throwCheirality
If true, re-throws Cheirality exceptions (default: false)
bool triangulateAndComputeJacobiansSVD(FBlocks &Fs, Matrix &Enull, Vector &b, const Values &values) const
takes values
~SmartStereoProjectionFactor() override
Base class for smart factors This base class has no internal point, but it has a measurement, noise model and an optional sensor pose. This class mainly computes the derivatives and returns them as a variety of factors. The methods take a Cameras argument, which should behave like PinholeCamera, and the value of a point, which is kept in the base class.
const SmartStereoProjectionParams params_
TriangulationResult point() const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Class compose(const Class &g) const
CameraSet< StereoCamera > Cameras
Vector of cameras.
Vector reprojectionErrorAfterTriangulation(const Values &values) const
Calculate vector of re-projection errors, before applying noise model.
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
void computeJacobiansWithTriangulatedPoint(FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras) const
Functions for triangulation.
bool isPointBehindCamera() const
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
LinearizationMode linearizationMode
How to linearize the factor.
static SmartStereoProjectionParams params
TriangulationResult triangulateSafe(const CameraSet< CAMERA > &cameras, const typename CAMERA::MeasurementVector &measured, const TriangulationParameters ¶ms)
triangulateSafe: extensive checking of the outcome
CameraSet< MonoCamera > MonoCameras
boost::shared_ptr< JacobianFactor > createJacobianSVDFactor(const Cameras &cameras, const Point3 &point, double lambda=0.0) const
void serialize(ARCHIVE &ar, const unsigned int)
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Pose3 body_P_sensor() const
A Stereo Camera based on two Simple Cameras.
void correctForMissingMeasurements(const Cameras &cameras, Vector &ue, boost::optional< typename Cameras::FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const override
void computeJacobians(FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras, const POINT &point) const
static const int Dim
Camera dimension.
double totalReprojectionError(const Cameras &cameras, const POINT &point) const
friend class boost::serialization::access
Serialization function.
void whitenJacobians(FBlocks &F, Matrix &E, Vector &b) const
Whiten the Jacobians computed by computeJacobians using noiseModel_.
bool triangulateAndComputeE(Matrix &E, const Cameras &cameras) const
TriangulationResult result_
result from triangulateSafe
Point2Vector MeasurementVector
SmartStereoProjectionFactor(const SharedNoiseModel &sharedNoiseModel, const SmartStereoProjectionParams ¶ms=SmartStereoProjectionParams(), const boost::optional< Pose3 > body_P_sensor=boost::none)
The matrix class, also used for vectors and row-vectors.
Vector unwhitenedError(const Cameras &cameras, const POINT &point, boost::optional< typename Cameras::FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
boost::shared_ptr< GaussianFactor > linearize(const Values &values) const override
linearize
utility functions for loading datasets
bool isDegenerate() const
bool isValid() const
Is result valid?
static const int ZDim
Measurement dimension.
noiseModel::Base::shared_ptr SharedNoiseModel
SmartProjectionParams SmartStereoProjectionParams
void computeJacobiansSVD(FBlocks &Fs, Matrix &Enull, Vector &b, const Cameras &cameras, const POINT &point) const
SVD version.
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b)
double retriangulationThreshold