33 static const double rankTol = 1.0;
35 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 std::function<Vector(Point3)>
f =
134 std::bind(&SmartFactor::whitenedError<Point3>, factor, cameras, std::placeholders::_1);
145 Matrix expectedE = sigma * numericalDerivative11<Vector, Point3>(
f, *
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);
321 values.
insert(
x3, pose_above * noise_pose);
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 auto 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 std::shared_ptr<RegularHessianFactor<6> > actual =
409 smartFactor1->createHessianFactor(cameras, 0.0);
449 Matrix3
P = (E.transpose() *
E).
inverse();
453 std::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 std::shared_ptr<RegularImplicitSchurFactor<Camera> > actual =
471 smartFactor1->createRegularImplicitSchurFactor(cameras, 0.0);
484 double s = sigma *
sin(M_PI_4);
489 std::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);
538 values.
insert(x3, pose_above * noise_pose);
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);
601 values.
insert(x3, pose_above * noise_pose);
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);
659 values.
insert(x3, pose_above * noise_pose);
673 double excludeLandmarksFutherThanDist = 1e10;
674 double dynamicOutlierRejectionThreshold = 1;
679 Point3 landmark4(5, -0.5, 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);
777 values.
insert(x3, pose_above * noise_pose);
808 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
810 graph.
addPrior(x2, pose_right, noisePrior);
816 values.
insert(x2, pose_right);
817 values.
insert(x3, pose_above * noise_pose);
820 values.
insert(
L(3), landmark3);
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 std::shared_ptr<GaussianFactor>
factor1 = smartFactor1->linearize(values);
891 std::shared_ptr<GaussianFactor>
factor2 = smartFactor2->linearize(values);
892 std::shared_ptr<GaussianFactor>
factor3 = smartFactor3->linearize(values);
894 Matrix CumulativeInformation = factor1->information() + factor2->information()
895 + factor3->information();
897 std::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 std::shared_ptr<GaussianFactor> factor = smartFactor1->linearize(values);
1090 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
1095 smartFactorInstance->add(measurements_cam1, views);
1102 std::shared_ptr<GaussianFactor> factor = smartFactorInstance->linearize(
1112 std::shared_ptr<GaussianFactor> factorRot = smartFactorInstance->linearize(
1126 std::shared_ptr<GaussianFactor> factorRotTran =
1127 smartFactorInstance->linearize(tranValues);
1148 smartFactor->add(measurements_cam1, views);
1153 values.
insert(x3, cam3.pose());
1155 std::shared_ptr<GaussianFactor> factor = smartFactor->linearize(values);
1164 std::shared_ptr<GaussianFactor> factorRot =
1165 smartFactor->linearize(rotValues);
1178 std::shared_ptr<GaussianFactor> factorRotTran = smartFactor->linearize(
1200 Point3 landmark3(3, 0, 3.0);
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);
1236 values.
insert(x3, pose_above * noise_pose);
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));
1265 Point3 landmark3(3, 0, 3.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)));
Base::Cameras cameras(const Values &values) const override
void computeJacobians(FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras, const POINT &point) const
bool triangulateAndComputeE(Matrix &E, const Cameras &cameras) const
static PinholeCamera< Cal3_S2 > cam1(pose3, cal1)
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
virtual const Values & optimize()
Camera cam3(interp_pose3, sharedK)
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
noiseModel::Diagonal::shared_ptr model
const ValueType at(Key j) const
void setRetriangulationThreshold(double retriangulationTh)
static StereoCamera cam2(pose3, cal4ptr)
#define DOUBLES_EQUAL(expected, actual, threshold)
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
static const Camera level_camera(level_pose, K2)
TEST(SmartProjectionPoseFactor, Constructor)
void setEnableEPI(bool enableEPI)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
Rot2 R(Rot2::fromAngle(0.1))
Jet< T, N > sin(const Jet< T, N > &f)
noiseModel::Isotropic::shared_ptr SharedIsotropic
static const std::shared_ptr< Cal3Bundler > sharedBundlerK(new Cal3Bundler(500, 1e-3, 1e-3, 1000, 2000))
Matrix information() const override
Some functions to compute numerical derivatives.
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
iterator insert(const std::pair< Key, Vector > &key_value)
static const Camera level_camera_right(pose_right, K2)
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
Point2 landmark1(5.0, 1.5)
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
Pose3 inverse() const
inverse transformation with derivatives
static const SmartProjectionParams params
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
const Pose3 & pose() const
pose
void setRankTolerance(double rankTol)
Implements a prior on the translation component of a pose.
static const double rankTol
Point2 project(const Point3 &pw, OptionalJacobian< 2, 6 > Dpose={}, OptionalJacobian< 2, 3 > Dpoint={}, OptionalJacobian< 2, DimK > Dcal={}) const
project a 3D point from world coordinates into the image
Point2 landmark2(7.0, 1.5)
double getRetriangulationThreshold() const
std::shared_ptr< Cal3_S2 > shared_ptr
const Pose3 & pose() const
return pose, constant version
SmartProjectionPoseFactor< Cal3_S2 > SmartFactor
#define EXPECT(condition)
static Pose3 pose3(rt3, pt3)
Matrix information() const override
static Point2 measurement1(323.0, 240.0)
void projectToMultipleCameras(const CAMERA &cam1, const CAMERA &cam2, const CAMERA &cam3, Point3 landmark, typename CAMERA::MeasurementVector &measurements_cam)
LevenbergMarquardtParams lmParams
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.)
The most common 5DOF 3D->2D calibration.
StereoPoint2 project(const Point3 &point) const
Project 3D point to StereoPoint2 (uL,uR,v)
double error(const Values &values) const
Class compose(const Class &g) const
static const Cal3_S2::shared_ptr sharedK(new Cal3_S2(fov, w, h))
Reprojection of a LANDMARK to a 2D point.
Pose3 x3(Rot3::Ypr(M_PI/4.0, 0.0, 0.0), l2)
double error(const Values &values) const override
noiseModel::Diagonal::shared_ptr SharedDiagonal
Calibration used by Bundler.
TriangulationResult point() const
void setDegeneracyMode(DegeneracyMode degMode)
void add(const Z &measured, const Key &key)
Matrix information() const override
Compute full information matrix
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
Pose3 g1(Rot3(), Point3(100.0, 0.0, 300.0))
static const Point2 level_uv_right
static const double sigma
void insert(Key j, const Value &val)
void setLinearizationMode(LinearizationMode linMode)
static const Cal3_S2::shared_ptr sharedK2(new Cal3_S2(1500, 1200, 0, 640, 480))
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
The matrix class, also used for vectors and row-vectors.
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Pose3 g2(g1.expmap(h *V1_g1))
void setDynamicOutlierRejectionThreshold(double dynOutRejectionThreshold)
static const Point2 level_uv
double totalReprojectionError(const Cameras &cameras, std::optional< Point3 > externalPoint={}) const
Vector unwhitenedError(const Cameras &cameras, const POINT &point, typename Cameras::FBlocks *Fs=nullptr, Matrix *E=nullptr) const