27 #include <boost/assign/std/map.hpp> 38 template<
class CALIBRATION>
44 Pose3 perturbedCameraPose = cameraPose.
compose(noise_pose);
48 CALIBRATION perturbedCalibration = camera.
calibration().retract(d);
58 Camera actualCamera(perturbed_level_pose,
K2);
114 double expectedError = 0.0;
118 factor1->reprojectionErrorAfterTriangulation(values), 1
e-7));
133 values.
insert(
c2, perturbed_level_camera_right);
136 factor1->add(level_uv,
c1);
137 factor1->add(level_uv_right,
c2);
140 EXPECT(!factor1->point());
142 double expectedError = 58640;
143 double actualError1 = factor1->error(values);
147 CHECK(factor1->point());
153 expected << -7, 235, 58, -242;
156 Vector actual = factor1->whitenedError(cameras1, point1);
161 measurements.push_back(level_uv);
162 measurements.push_back(level_uv_right);
166 factor2->add(measurements, views);
168 double actualError2 = factor2->error(values);
178 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
188 smartFactor1->add(measurements_cam1, views);
189 smartFactor2->add(measurements_cam2, views);
190 smartFactor3->add(measurements_cam3, views);
197 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6 + 5, 1
e-5);
210 EXPECT(!smartFactor1->point());
211 EXPECT(!smartFactor2->point());
212 EXPECT(!smartFactor3->point());
219 CHECK(smartFactor1->point());
220 CHECK(smartFactor2->point());
221 CHECK(smartFactor3->point());
235 expected << 256, 29, -26, 29, -206, -202;
241 Vector actual = smartFactor1->whitenedError(cameras1, point1);
247 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
248 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
277 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
285 for (
size_t i = 0;
i < 3; ++
i) {
289 smartFactor1->add(track1);
292 for (
size_t i = 0;
i < 3; ++
i) {
296 smartFactor2->add(track2);
299 smartFactor3->add(measurements_cam3, views);
301 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6 + 5, 1
e-5);
319 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
321 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
346 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3,
347 measurements_cam4, measurements_cam5;
359 smartFactor1->add(measurements_cam1, views);
362 smartFactor2->add(measurements_cam2, views);
365 smartFactor3->add(measurements_cam3, views);
368 smartFactor4->add(measurements_cam4, views);
371 smartFactor5->add(measurements_cam5, views);
373 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6 + 5, 1
e-5);
396 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
398 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
423 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3,
424 measurements_cam4, measurements_cam5;
436 smartFactor1->add(measurements_cam1, views);
439 smartFactor2->add(measurements_cam2, views);
442 smartFactor3->add(measurements_cam3, views);
445 smartFactor4->add(measurements_cam4, views);
448 smartFactor5->add(measurements_cam5, views);
450 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(9, 1
e-6);
472 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
474 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
496 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3,
497 measurements_cam4, measurements_cam5;
509 smartFactor1->add(measurements_cam1, views);
512 smartFactor2->add(measurements_cam2, views);
515 smartFactor3->add(measurements_cam3, views);
518 smartFactor4->add(measurements_cam4, views);
521 smartFactor5->add(measurements_cam5, views);
523 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(9, 1
e-6);
545 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
547 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
576 double actualError = factor1->error(values);
578 double expectedError = 0.0;
582 if (factor1->point())
583 oldPoint = *(factor1->point());
585 Point3 expectedPoint(0,0,0);
586 if (factor1->point(values))
587 expectedPoint = *(factor1->point(values));
605 double expectedError = factor1->error(values);
606 double expectedErrorGraph = smartGraph.
error(values);
607 Point3 expectedPoint(0,0,0);
608 if (factor1->point())
609 expectedPoint = *(factor1->point());
622 double actualError = 0.5 * (e1.squaredNorm() + e2.squaredNorm());
623 double actualErrorGraph = generalGraph.
error(values);
644 Matrix expectedHessian = smartGraph.
linearize(values)->hessian().first;
645 Vector expectedInfoVector = smartGraph.
linearize(values)->hessian().second;
646 Point3 expectedPoint(0,0,0);
647 if (factor1->point())
648 expectedPoint = *(factor1->point());
659 Matrix actualFullHessian = generalGraph.
linearize(values)->hessian().first;
660 Matrix actualFullInfoVector = generalGraph.
linearize(values)->hessian().second;
661 Matrix actualHessian = actualFullHessian.block(0, 0, 18, 18)
662 - actualFullHessian.block(0, 18, 18, 3)
663 * (actualFullHessian.block(18, 18, 3, 3)).
inverse()
664 * actualFullHessian.block(18, 0, 3, 18);
665 Vector actualInfoVector = actualFullInfoVector.block(0, 0, 18, 1)
666 - actualFullHessian.block(0, 18, 18, 3)
667 * (actualFullHessian.block(18, 18, 3, 3)).
inverse()
668 * actualFullInfoVector.block(18, 0, 3, 1);
741 factor1->error(values);
743 if (factor1->point())
744 point = *(factor1->point());
746 factor1->computeJacobians(Fs, expectedE, expectedb, cameras, point);
754 Matrix actualFullHessian = generalGraph.
linearize(values)->hessian().first;
755 Matrix actualVinv = (actualFullHessian.block(18, 18, 3, 3)).
inverse();
757 Matrix3 expectedVinv = factor1->PointCov(expectedE);
796 implicitFactor->linearize(values);
797 CHECK(gaussianImplicitSchurFactor);
799 Implicit9& implicitSchurFactor =
800 dynamic_cast<Implicit9&
>(*gaussianImplicitSchurFactor);
803 (
Vector(9) << 1, 2, 3, 4, 5, 6, 7, 8, 9).finished())(
c2,
804 (
Vector(9) << 11, 12, 13, 14, 15, 16, 17, 18, 19).finished());
809 implicitSchurFactor.multiplyHessianAdd(alpha, x, yExpected);
void print(const Matrix &A, const string &s, ostream &stream)
BOOST_CLASS_EXPORT_GUID(gtsam::noiseModel::Constrained,"gtsam_noiseModel_Constrained")
static PinholeCamera< Cal3_S2 > cam1(pose3, cal1)
const Pose3 & pose() const
return pose
virtual const Values & optimize()
void serialize(Archive &ar, Eigen::Matrix< Scalar_, Rows_, Cols_, Ops_, MaxRows_, MaxCols_ > &m, const unsigned int version)
static int runAllTests(TestResult &result)
Camera cam3(pose_above, K2)
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const override
Camera level_camera_right(pose_right, K2)
void insert(Key j, const Value &val)
static StereoCamera cam2(pose3, cal4ptr)
bool equalsObj(const T &input=T())
#define DOUBLES_EQUAL(expected, actual, threshold)
Point3 landmark5(10,-0.5, 1.2)
void setEnableEPI(bool enableEPI)
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
static const bool isDebugTest
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
CAMERA perturbCameraPose(const CAMERA &camera)
const Calibration & calibration() const override
return calibration
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
static const Symbol l1('l', 1)
Point3 landmark3(3, 0, 3.0)
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
Point2 landmark1(5.0, 1.5)
Vector reprojectionError(const POINT &point, const ZVector &measured, boost::optional< FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
Calculate vector [project2(point)-z] of re-projection errors.
bool equalsXML(const T &input=T())
bool equalsBinary(const T &input=T())
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
Point3 landmark4(10, 0.5, 1.2)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
void setRankTolerance(double rankTol)
static const Cal3Bundler K2(625, 1e-3, 1e-3)
Smart factor on cameras (pose + calibration)
Point2 landmark2(7.0, 1.5)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Class compose(const Class &g) const
Define the structure for the 3D points.
const ValueType at(Key j) const
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
SmartProjectionPoseFactor< Cal3_S2 > SmartFactor
#define EXPECT(condition)
PinholeCamera< CALIBRATION > perturbCameraPoseAndCalibration(const PinholeCamera< CALIBRATION > &camera)
void projectToMultipleCameras(const CAMERA &cam1, const CAMERA &cam2, const CAMERA &cam3, Point3 landmark, typename CAMERA::MeasurementVector &measurements_cam)
static const Symbol l3('l', 3)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static SmartStereoProjectionParams params
static const double rankTol
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
static SharedNoiseModel unit2(noiseModel::Unit::Create(2))
noiseModel::Diagonal::shared_ptr SharedDiagonal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
static const Symbol l2('l', 2)
void setDegeneracyMode(DegeneracyMode degMode)
LevenbergMarquardtParams lmParams
void add(const Z &measured, const Key &key)
Vector evaluateError(const CAMERA &camera, const LANDMARK &point, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Point2 project(const Point3 &pw, OptionalJacobian< 2, 6 > Dpose=boost::none, OptionalJacobian< 2, 3 > Dpoint=boost::none, OptionalJacobian< 2, DimK > Dcal=boost::none) const
project a 3D point from world coordinates into the image
A Gaussian factor using the canonical parameters (information form)
JacobianFactor factor2(keyX, A21, keyY, A22, b2, noiseModel::Isotropic::Sigma(2, sigma2))
void setLinearizationMode(LinearizationMode linMode)
TEST(SmartProjectionFactor, perturbCameraPose)
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
const Point3 point1(3.0, 4.0, 2.0)
double error(const Values &values) const
static const Point2 measurement1(323.0, 240.0)
VerbosityLM verbosityLM
The verbosity level for Levenberg-Marquardt (default: SILENT), see also NonlinearOptimizerParams::ver...
boost::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
static const CalibratedCamera camera(kDefaultPose)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Camera level_camera(level_pose, K2)
std::vector< SfmMeasurement > measurements
The 2D image projections (id,(u,v))
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
std::uint64_t Key
Integer nonlinear key type.
noiseModel::Base::shared_ptr SharedNoiseModel
size_t maxIterations
The maximum iterations to stop iterating (default 100)
JacobianFactor factor1(keyX, A11, b1, noiseModel::Isotropic::Sigma(2, sigma1))