30 #include <boost/assign.hpp> 31 #include <boost/assign/std/vector.hpp> 34 using namespace gtsam;
40 boost::make_shared<Cal3_S2>(1500, 1200, 0, 640, 480);
60 TEST( triangulation, twoPoses) {
66 measurements +=
z1,
z2;
68 double rank_tol = 1
e-9;
72 boost::optional<Point3> actual1 =
78 boost::optional<Point3> actual2 =
83 measurements.at(0) +=
Point2(0.1, 0.5);
84 measurements.at(1) +=
Point2(-0.2, 0.3);
86 boost::optional<Point3> actual3 =
92 boost::optional<Point3> actual4 =
99 TEST( triangulation, twoPosesBundler) {
101 boost::shared_ptr<Cal3Bundler> bundlerCal =
102 boost::make_shared<Cal3Bundler>(1500, 0, 0, 640, 480);
114 measurements +=
z1,
z2;
117 double rank_tol = 1
e-9;
119 boost::optional<Point3> actual =
124 measurements.at(0) +=
Point2(0.1, 0.5);
125 measurements.at(1) +=
Point2(-0.2, 0.3);
127 boost::optional<Point3> actual2 =
133 TEST( triangulation, fourPoses) {
138 measurements +=
z1,
z2;
145 measurements.at(0) +=
Point2(0.1, 0.5);
146 measurements.at(1) +=
Point2(-0.2, 0.3);
148 boost::optional<Point3> actual2 =
158 measurements += z3 +
Point2(0.1, -0.1);
160 boost::optional<Point3> triangulated_3cameras =
170 Pose3 pose4 = Pose3(Rot3::Ypr(
M_PI / 2, 0., -
M_PI / 2),
Point3(0, 0, 1));
173 #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION 177 measurements +=
Point2(400, 400);
185 TEST( triangulation, fourPoses_distinct_Ks) {
202 measurements +=
z1,
z2;
204 boost::optional<Point3> actual =
209 measurements.at(0) +=
Point2(0.1, 0.5);
210 measurements.at(1) +=
Point2(-0.2, 0.3);
212 boost::optional<Point3> actual2 =
218 Cal3_S2 K3(700, 500, 0, 640, 480);
223 measurements += z3 +
Point2(0.1, -0.1);
225 boost::optional<Point3> triangulated_3cameras =
231 measurements, 1
e-9,
true);
235 Pose3 pose4 = Pose3(Rot3::Ypr(
M_PI / 2, 0., -
M_PI / 2),
Point3(0, 0, 1));
239 #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION 243 measurements +=
Point2(400, 400);
250 TEST( triangulation, outliersAndFarLandmarks) {
267 measurements +=
z1,
z2;
269 double landmarkDistanceThreshold = 10;
275 landmarkDistanceThreshold = 4;
282 Cal3_S2 K3(700, 500, 0, 640, 480);
287 measurements += z3 +
Point2(10, -10);
289 landmarkDistanceThreshold = 10;
290 double outlierThreshold = 100;
296 outlierThreshold = 5;
303 TEST( triangulation, twoIdenticalPoses) {
314 measurements +=
z1,
z1;
321 TEST( triangulation, onePose) {
329 measurements +=
Point2(0,0);
336 TEST( triangulation, StereotriangulateNonlinear ) {
338 auto stereoK = boost::make_shared<Cal3_S2Stereo>(1733.75, 1733.75, 0, 689.645, 508.835, 0.0699612);
342 m1 << 0.796888717, 0.603404026, -0.0295271487, 46.6673779,
343 0.592783835, -0.77156583, 0.230856632, 66.2186159,
344 0.116517574, -0.201470143, -0.9725393, -4.28382528,
347 m2 << -0.955959025, -0.29288915, -0.0189328569, 45.7169799,
348 -0.29277519, 0.947083213, 0.131587097, 65.843136,
349 -0.0206094928, 0.131334858, -0.991123524, -4.3525033,
358 measurements +=
StereoPoint2(226.936, 175.212, 424.469);
359 measurements +=
StereoPoint2(339.571, 285.547, 669.973);
384 const SharedDiagonal posePrior = noiseModel::Isotropic::Sigma(6, 1
e-9);
static Point2 project2(const CalibratedCamera &camera, const Point3 &point)
virtual const Values & optimize()
static int runAllTests(TestResult &result)
void insert(Key j, const Value &val)
Base class to create smart factors on poses or cameras.
PinholeCamera< Cal3_S2 > camera1(pose1,*sharedCal)
static const Rot3 upright
Point3 triangulateNonlinear(const std::vector< Pose3 > &poses, boost::shared_ptr< CALIBRATION > sharedCal, const Point2Vector &measurements, const Point3 &initialEstimate)
static const Point3 landmark(5, 0.5, 1.2)
#define CHECK_EXCEPTION(condition, exception_name)
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
static const boost::shared_ptr< Cal3_S2 > sharedCal
std::vector< StereoPoint2 > StereoPoint2Vector
static const CalibratedCamera camera3(pose1)
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
PinholeCamera< Cal3_S2 > camera2(pose2,*sharedCal)
static const Cal3Bundler K2(625, 1e-3, 1e-3)
Base class for all pinhole cameras.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
TEST(triangulation, twoPoses)
Point3 triangulatePoint3(const std::vector< Pose3 > &poses, boost::shared_ptr< CALIBRATION > sharedCal, const Point2Vector &measurements, double rank_tol=1e-9, bool optimize=false)
const ValueType at(Key j) const
void addExpressionFactor(const SharedNoiseModel &R, const T &z, const Expression< T > &h)
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
#define EXPECT(condition)
static Pose3 pose3(rt3, pt3)
Functions for triangulation.
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 K1(new Cal3_S2(fov, w, h))
Exception thrown by triangulateDLT when SVD returns rank < 3.
static SmartStereoProjectionParams params
TriangulationResult triangulateSafe(const CameraSet< CAMERA > &cameras, const typename CAMERA::MeasurementVector &measured, const TriangulationParameters ¶ms)
triangulateSafe: extensive checking of the outcome
Exception thrown by triangulateDLT when landmark is behind one or more of the cameras.
noiseModel::Diagonal::shared_ptr SharedDiagonal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
A Stereo Camera based on two Simple Cameras.
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
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
Calibration used by Bundler.
noiseModel::Base::shared_ptr SharedNoiseModel