29 static const bool isDebugTest =
false;
31 static const Key c1 = 1, c2 = 2, c3 = 3;
33 static const double rankTol = 1.0;
36 template<
class CALIBRATION>
42 Pose3 perturbedCameraPose = cameraPose.
compose(noise_pose);
46 CALIBRATION perturbedCalibration = camera.
calibration().retract(d);
56 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);
207 initial.
at<
Camera>(c3).
print(
"Smart: Pose3 before optimization: ");
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;
261 result.
at<
Camera>(c3).
print(
"Smart: Pose3 after optimization: ");
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);
315 values.
at<
Camera>(c3).
print(
"Smart: Pose3 before optimization: ");
319 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
321 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
331 result.
at<
Camera>(c3).
print(
"Smart: Pose3 after optimization: ");
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);
389 values.
at<
Camera>(c3).
print(
"Smart: Pose3 before optimization: ");
396 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
398 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
408 result.
at<
Camera>(c3).
print(
"Smart: Pose3 after optimization: ");
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);
465 values.
at<
Camera>(c3).
print(
"Smart: Pose3 before optimization: ");
472 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
474 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
481 result.
at<
Camera>(c3).
print(
"Smart: Pose3 after optimization: ");
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);
538 values.
at<
Camera>(c3).
print(
"Smart: Pose3 before optimization: ");
545 lmParams.
verbosityLM = LevenbergMarquardtParams::TRYLAMBDA;
547 lmParams.
verbosity = NonlinearOptimizerParams::ERROR;
554 result.
at<
Camera>(c3).
print(
"Smart: Pose3 after optimization: ");
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);
784 GaussianFactor::shared_ptr gaussianHessianFactor = explicitFactor->linearize(
795 GaussianFactor::shared_ptr gaussianImplicitSchurFactor =
796 implicitFactor->linearize(values);
797 CHECK(gaussianImplicitSchurFactor);
799 Implicit9& implicitSchurFactor =
800 dynamic_cast<Implicit9&
>(*gaussianImplicitSchurFactor);
803 {c1, (
Vector(9) << 1, 2, 3, 4, 5, 6, 7, 8, 9).finished()},
804 {c2, (
Vector(9) << 11, 12, 13, 14, 15, 16, 17, 18, 19).finished()}};
809 implicitSchurFactor.multiplyHessianAdd(alpha,
x, yExpected);
Vector evaluateError(const CAMERA &camera, const LANDMARK &point, OptionalMatrixType H1, OptionalMatrixType H2) const override
virtual const Values & optimize()
static int runAllTests(TestResult &result)
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const override
const ValueType at(Key j) const
#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)
void setEnableEPI(bool enableEPI)
Vector reprojectionError(const POINT &point, const ZVector &measured, FBlocks *Fs=nullptr, Matrix *E=nullptr) const
Calculate vector [project2(point)-z] of re-projection errors.
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
static const Camera cam1(level_pose, K2)
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
CAMERA perturbCameraPose(const CAMERA &camera)
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
static const Camera level_camera_right(pose_right, K2)
const Calibration & calibration() const override
return calibration
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
Point2 landmark1(5.0, 1.5)
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
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
return pose
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
void setRankTolerance(double rankTol)
Smart factor on cameras (pose + calibration)
static const Camera cam3(pose_above, K2)
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)
static const Cal3_S2 K2(1500, 1200, 0, w, h)
#define EXPECT(condition)
static Point2 measurement1(323.0, 240.0)
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)
LevenbergMarquardtParams lmParams
std::vector< SfmMeasurement > measurements
The 2D image projections (id,(u,v))
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
double error(const Values &values) const
Class compose(const Class &g) const
SmartProjectionFactor< Camera > SmartFactor
noiseModel::Diagonal::shared_ptr SharedDiagonal
Calibration used by Bundler.
void setDegeneracyMode(DegeneracyMode degMode)
void add(const Z &measured, const Key &key)
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
static const Camera cam2(pose_right, K2)
static const Point2 level_uv_right
A Gaussian factor using the canonical parameters (information form)
void insert(Key j, const Value &val)
void setLinearizationMode(LinearizationMode linMode)
TEST(SmartProjectionFactor, perturbCameraPose)
const Point3 point1(3.0, 4.0, 2.0)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
VerbosityLM verbosityLM
The verbosity level for Levenberg-Marquardt (default: SILENT), see also NonlinearOptimizerParams::ver...
static const CalibratedCamera camera(kDefaultPose)
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
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
static const Point2 level_uv
std::uint64_t Key
Integer nonlinear key type.
size_t maxIterations
The maximum iterations to stop iterating (default 100)