29 #include <boost/assign/std/map.hpp> 36 static const double sigma = 0.1;
117 factor.
add(level_uv,
x1);
118 factor.
add(level_uv_right,
x2);
124 double actualError = factor.
error(values);
125 double expectedError = 0.0;
133 boost::function<Vector(Point3)>
f =
134 boost::bind(&SmartFactor::whitenedError<Point3>, factor, cameras, _1);
141 boost::optional<Point3>
point = factor.
point();
160 double actualError3 = b.squaredNorm();
171 Point2 pixelError(0.2, 0.2);
182 factor->add(level_uv,
x1);
183 factor->add(level_uv_right,
x2);
185 double actualError1 = factor->error(values);
189 measurements.push_back(level_uv);
190 measurements.push_back(level_uv_right);
194 factor2->add(measurements, views);
195 double actualError2 = factor2->error(values);
208 Pose3 wTb1 =
cam1.pose() * sensor_T_body;
215 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
231 smartFactor1.
add(measurements_cam1, views);
234 smartFactor2.
add(measurements_cam2, views);
237 smartFactor3.
add(measurements_cam3, views);
239 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
253 gtValues.
insert(x3, wTb3);
254 double actualError = graph.
error(gtValues);
255 double expectedError = 0.0;
265 values.
insert(x3, wTb3 * noise_pose);
278 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
291 smartFactor1->add(measurements_cam1, views);
294 smartFactor2->add(measurements_cam2, views);
297 smartFactor3->add(measurements_cam3, views);
299 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
325 Rot3(0, -0.0314107591, 0.99950656, -0.99950656, -0.0313952598,
326 -0.000986635786, 0.0314107591, -0.999013364, -0.0313952598),
352 measurements_cam1.push_back(
cam1.project(landmark1));
353 measurements_cam1.push_back(cam2.project(landmark1));
359 smartFactor1->add(measurements_cam1, views);
362 cameras.push_back(
cam1);
363 cameras.push_back(cam2);
366 CHECK(smartFactor1->triangulateSafe(cameras));
367 CHECK(!smartFactor1->isDegenerate());
368 CHECK(!smartFactor1->isPointBehindCamera());
369 boost::optional<Point3>
p = smartFactor1->point();
377 zeroDelta.
insert(x2, delta);
382 perturbedDelta.
insert(x2, delta);
383 double expectedError = 2500;
387 A1 << -10, 0, 0, 0, 1, 0;
388 A2 << 10, 0, 1, 0, -1, 0;
391 Matrix expectedInformation;
394 Matrix66 G11 = 0.5 * A1.transpose() * A1;
395 Matrix66 G12 = 0.5 * A1.transpose() * A2;
396 Matrix66 G22 = 0.5 * A2.transpose() * A2;
408 boost::shared_ptr<RegularHessianFactor<6> > actual =
409 smartFactor1->createHessianFactor(cameras, 0.0);
449 Matrix3
P = (E.transpose() *
E).
inverse();
453 boost::shared_ptr<JacobianFactorQ<6, 2> > actualQ =
454 smartFactor1->createJacobianQFactor(cameras, 0.0);
462 model->WhitenSystem(E, b);
463 Matrix3 whiteP = (E.transpose() *
E).
inverse();
464 Fs[0] = model->Whiten(Fs[0]);
465 Fs[1] = model->Whiten(Fs[1]);
470 boost::shared_ptr<RegularImplicitSchurFactor<Camera> > actual =
471 smartFactor1->createRegularImplicitSchurFactor(cameras, 0.0);
489 boost::shared_ptr<JacobianFactor> actual =
490 smartFactor1->createJacobianSVDFactor(cameras, 0.0);
506 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
514 smartFactor1->add(measurements_cam1, views);
517 smartFactor2->add(measurements_cam2, views);
520 smartFactor3->add(measurements_cam3, views);
522 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
542 Rot3(1.11022302
e-16, -0.0314107591, 0.99950656, -0.99950656,
543 -0.0313952598, -0.000986635786, 0.0314107591, -0.999013364,
544 -0.0313952598),
Point3(0.1, -0.1, 1.9)),
560 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
576 smartFactor1->add(measurements_cam1, views);
580 smartFactor2->add(measurements_cam2, views);
584 smartFactor3->add(measurements_cam3, views);
586 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
614 double excludeLandmarksFutherThanDist = 2;
618 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
634 smartFactor1->add(measurements_cam1, views);
638 smartFactor2->add(measurements_cam2, views);
642 smartFactor3->add(measurements_cam3, views);
644 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
673 double excludeLandmarksFutherThanDist = 1e10;
674 double dynamicOutlierRejectionThreshold = 1;
681 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3,
689 measurements_cam4.at(0) = measurements_cam4.at(0) +
Point2(10, 10);
698 smartFactor1->add(measurements_cam1, views);
702 smartFactor2->add(measurements_cam2, views);
706 smartFactor3->add(measurements_cam3, views);
710 smartFactor4->add(measurements_cam4, views);
712 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
741 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
753 smartFactor1->add(measurements_cam1, views);
757 smartFactor2->add(measurements_cam2, views);
761 smartFactor3->add(measurements_cam3, views);
763 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
808 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
841 *
Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0, 0, 0));
842 Pose3
pose3 = pose2 * Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0, 0, 0));
846 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
858 smartFactor1->add(measurements_cam1, views);
862 smartFactor2->add(measurements_cam2, views);
866 smartFactor3->add(measurements_cam3, views);
874 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
880 values.
insert(x3, pose3 * noise_pose);
884 Rot3(0.00563056869, -0.130848107, 0.991386438, -0.991390265,
885 -0.130426831, -0.0115837907, 0.130819108, -0.98278564,
887 Point3(0.0897734171, -0.110201006, 0.901022872)),
888 values.
at<Pose3>(x3)));
890 boost::shared_ptr<GaussianFactor>
factor1 = smartFactor1->linearize(values);
891 boost::shared_ptr<GaussianFactor>
factor2 = smartFactor2->linearize(values);
892 boost::shared_ptr<GaussianFactor>
factor3 = smartFactor3->linearize(values);
895 + factor3->information();
897 boost::shared_ptr<GaussianFactorGraph> GaussianGraph = graph.
linearize(
899 Matrix GraphInformation = GaussianGraph->hessian().first;
904 Matrix AugInformationMatrix = factor1->augmentedInformation()
905 + factor2->augmentedInformation() + factor3->augmentedInformation();
908 Vector InfoVector = AugInformationMatrix.block(0, 18, 18, 1);
922 Pose3
pose3 = pose2 * Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0,0,0));
938 smartFactor1->add(measurements_cam1, views);
942 smartFactor2->add(measurements_cam2, views);
944 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
945 const SharedDiagonal noisePriorTranslation = noiseModel::Isotropic::Sigma(3, 0.10);
955 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
959 values.
insert(x2, pose2 * noise_pose);
960 values.
insert(x3, pose3 * noise_pose);
978 *
Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0, 0, 0));
979 Pose3
pose3 = pose2 * Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0, 0, 0));
983 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
996 smartFactor1->add(measurements_cam1, views);
1000 smartFactor2->add(measurements_cam2, views);
1004 smartFactor3->add(measurements_cam3, views);
1006 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
1007 const SharedDiagonal noisePriorTranslation = noiseModel::Isotropic::Sigma(3,
1020 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
1024 values.
insert(x2, cam2.pose());
1025 values.
insert(x3, pose3 * noise_pose);
1029 Rot3(0.00563056869, -0.130848107, 0.991386438, -0.991390265,
1030 -0.130426831, -0.0115837907, 0.130819108, -0.98278564,
1032 Point3(0.0897734171, -0.110201006, 0.901022872)),
1033 values.
at<Pose3>(x3)));
1041 #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION 1043 Point3(0,0,1)), result.
at<Pose3>(x3)));
1062 measurements_cam1.push_back(cam1_uv1);
1063 measurements_cam1.push_back(cam2_uv1);
1066 smartFactor1->add(measurements_cam1, views);
1074 boost::shared_ptr<GaussianFactor> factor = smartFactor1->linearize(values);
1090 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
1095 smartFactorInstance->add(measurements_cam1, views);
1102 boost::shared_ptr<GaussianFactor> factor = smartFactorInstance->linearize(
1112 boost::shared_ptr<GaussianFactor> factorRot = smartFactorInstance->linearize(
1126 boost::shared_ptr<GaussianFactor> factorRotTran =
1127 smartFactorInstance->linearize(tranValues);
1148 smartFactor->add(measurements_cam1, views);
1153 values.
insert(x3, cam3.pose());
1155 boost::shared_ptr<GaussianFactor> factor = smartFactor->linearize(values);
1164 boost::shared_ptr<GaussianFactor> factorRot =
1165 smartFactor->linearize(rotValues);
1178 boost::shared_ptr<GaussianFactor> factorRotTran = smartFactor->linearize(
1202 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
1212 smartFactor1->add(measurements_cam1, views);
1215 smartFactor2->add(measurements_cam2, views);
1218 smartFactor3->add(measurements_cam3, views);
1220 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
1240 Rot3(0, -0.0314107591, 0.99950656, -0.99950656, -0.0313952598,
1241 -0.000986635786, 0.0314107591, -0.999013364, -0.0313952598),
1259 *
Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0, 0, 0));
1260 Pose3
pose3 = pose2 * Pose3(Rot3::RzRyRx(-0.05, 0.0, -0.05),
Point3(0, 0, 0));
1267 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
1280 smartFactor1->add(measurements_cam1, views);
1284 smartFactor2->add(measurements_cam2, views);
1288 smartFactor3->add(measurements_cam3, views);
1290 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
1291 const SharedDiagonal noisePriorTranslation = noiseModel::Isotropic::Sigma(3,
1304 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
1308 values.
insert(x2, cam2.pose());
1310 values.
insert(x3, pose3 * noise_pose);
1314 Rot3(0.00563056869, -0.130848107, 0.991386438, -0.991390265,
1315 -0.130426831, -0.0115837907, 0.130819108, -0.98278564,
1317 Point3(0.0897734171, -0.110201006, 0.901022872)),
1318 values.
at<Pose3>(x3)));
1327 Rot3(0.00563056869, -0.130848107, 0.991386438, -0.991390265,
1328 -0.130426831, -0.0115837907, 0.130819108, -0.98278564,
1330 Point3(0.0897734171, -0.110201006, 0.901022872)),
1331 values.
at<Pose3>(x3)));
1366 key_view.push_back(
Symbol(
'x', 1));
1367 meas_view.push_back(
Point2(10, 10));
1368 factor.
add(meas_view, key_view);
Base::Cameras cameras(const Values &values) const override
double totalReprojectionError(const Cameras &cameras, boost::optional< Point3 > externalPoint=boost::none) const
static PinholeCamera< Cal3_S2 > cam1(pose3, cal1)
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
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)
Camera level_camera_right(pose_right, K2)
void insert(Key j, const Value &val)
void setRetriangulationThreshold(double retriangulationTh)
static StereoCamera cam2(pose3, cal4ptr)
bool equalsObj(const T &input=T())
#define DOUBLES_EQUAL(expected, actual, threshold)
TEST(SmartProjectionPoseFactor, Constructor)
void setEnableEPI(bool enableEPI)
static const double sigma
static Point2 measurement1(323.0, 240.0)
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
Rot2 R(Rot2::fromAngle(0.1))
noiseModel::Isotropic::shared_ptr SharedIsotropic
Some functions to compute numerical derivatives.
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Point3 landmark3(3, 0, 3.0)
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
Point2 landmark1(5.0, 1.5)
bool equalsXML(const T &input=T())
bool equalsBinary(const T &input=T())
Point3 landmark4(10, 0.5, 1.2)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
JacobianFactor factor3(keyY, A32, keyZ, A33, b3, noiseModel::Isotropic::Sigma(2, sigma3))
BOOST_CLASS_EXPORT_GUID(gtsam::noiseModel::Constrained,"gtsam_noiseModel_Constrained")
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
void setRankTolerance(double rankTol)
static const double rankTol
Implements a prior on the translation component of a pose.
static boost::shared_ptr< Cal3Bundler > sharedBundlerK(new Cal3Bundler(500, 1e-3, 1e-3, 1000, 2000))
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
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
Pose3 inverse() const
inverse transformation with derivatives
const ValueType at(Key j) const
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
SmartProjectionPoseFactor< Cal3_S2 > SmartFactor
#define EXPECT(condition)
static Pose3 pose3(rt3, pt3)
static SharedIsotropic model(noiseModel::Isotropic::Sigma(2, sigma))
Matrix information() const override
void projectToMultipleCameras(const CAMERA &cam1, const CAMERA &cam2, const CAMERA &cam3, Point3 landmark, typename CAMERA::MeasurementVector &measurements_cam)
void setLandmarkDistanceThreshold(double landmarkDistanceThreshold)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static Cal3_S2::shared_ptr sharedK(new Cal3_S2(fov, w, h))
static SmartStereoProjectionParams params
Basic bearing factor from 2D measurement.
double error(const Values &values) const override
noiseModel::Diagonal::shared_ptr SharedDiagonal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
void computeJacobians(FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras, const POINT &point) const
void setDegeneracyMode(DegeneracyMode degMode)
LevenbergMarquardtParams lmParams
void add(const Z &measured, const Key &key)
Matrix information() const override
Compute full information matrix
double getRetriangulationThreshold() const
Pose3 g1(Rot3(), Point3(100.0, 0.0, 300.0))
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
static Cal3_S2::shared_ptr sharedK2(new Cal3_S2(1500, 1200, 0, 640, 480))
JacobianFactor factor2(keyX, A21, keyY, A22, b2, noiseModel::Isotropic::Sigma(2, sigma2))
void setLinearizationMode(LinearizationMode linMode)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
StereoPoint2 project(const Point3 &point) const
Project 3D point to StereoPoint2 (uL,uR,v)
double error(const Values &values) const
The matrix class, also used for vectors and row-vectors.
boost::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Vector unwhitenedError(const Cameras &cameras, const POINT &point, boost::optional< typename Cameras::FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
Pose3 g2(g1.expmap(h *V1_g1))
bool triangulateAndComputeE(Matrix &E, const Cameras &cameras) const
iterator insert(const std::pair< Key, Vector > &key_value)
const Pose3 & pose() const
pose
boost::shared_ptr< Cal3_S2 > shared_ptr
Camera level_camera(level_pose, K2)
void setDynamicOutlierRejectionThreshold(double dynOutRejectionThreshold)
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
Matrix information() const override
TriangulationResult point() const
noiseModel::Base::shared_ptr SharedNoiseModel
JacobianFactor factor1(keyX, A11, b1, noiseModel::Isotropic::Sigma(2, sigma1))