triangulation.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 
23 
24 namespace gtsam {
25 
27  const std::vector<Matrix34, Eigen::aligned_allocator<Matrix34>>& projection_matrices,
28  const Point2Vector& measurements, double rank_tol) {
29 
30  // number of cameras
31  size_t m = projection_matrices.size();
32 
33  // Allocate DLT matrix
34  Matrix A = Matrix::Zero(m * 2, 4);
35 
36  for (size_t i = 0; i < m; i++) {
37  size_t row = i * 2;
38  const Matrix34& projection = projection_matrices.at(i);
39  const Point2& p = measurements.at(i);
40 
41  // build system of equations
42  A.row(row) = p.x() * projection.row(2) - projection.row(0);
43  A.row(row + 1) = p.y() * projection.row(2) - projection.row(1);
44  }
45  int rank;
46  double error;
47  Vector v;
48  boost::tie(rank, error, v) = DLT(A, rank_tol);
49 
50  if (rank < 3)
52 
53  return v;
54 }
55 
56 Point3 triangulateDLT(const std::vector<Matrix34, Eigen::aligned_allocator<Matrix34>>& projection_matrices,
57  const Point2Vector& measurements, double rank_tol) {
58 
59  Vector4 v = triangulateHomogeneousDLT(projection_matrices, measurements, rank_tol);
60 
61  // Create 3D point from homogeneous coordinates
62  return Point3(v.head<3>() / v[3]);
63 }
64 
66 
74  Key landmarkKey) {
75  // Maybe we should consider Gauss-Newton?
79  params.lambdaInitial = 1;
80  params.lambdaFactor = 10;
81  params.maxIterations = 100;
82  params.absoluteErrorTol = 1.0;
86 
87  LevenbergMarquardtOptimizer optimizer(graph, values, params);
88  Values result = optimizer.optimize();
89 
90  return result.at<Point3>(landmarkKey);
91 }
92 
93 } // \namespace gtsam
Matrix3f m
boost::tuple< int, double, Vector > DLT(const Matrix &A, double rank_tol)
Definition: Matrix.cpp:567
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
Definition: base/Matrix.h:225
Vector4 triangulateHomogeneousDLT(const std::vector< Matrix34, Eigen::aligned_allocator< Matrix34 >> &projection_matrices, const Point2Vector &measurements, double rank_tol)
virtual const Values & optimize()
Vector2 Point2
Definition: Point2.h:27
ArrayXcf v
Definition: Cwise_arg.cpp:1
double lambdaFactor
The amount by which to multiply or divide lambda when adjusting lambda (default: 10.0)
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
leaf::MyValues values
Verbosity verbosity
The printing verbosity during optimization (default SILENT)
NonlinearFactorGraph graph
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
Base class for all pinhole cameras.
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Eigen::VectorXd Vector
Definition: Vector.h:38
Values result
const ValueType at(Key j) const
Definition: Values-inl.h:342
STL compatible allocator to use with types requiring a non standrad alignment.
Definition: Memory.h:721
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
Definition: Point2.h:42
Functions for triangulation.
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Exception thrown by triangulateDLT when SVD returns rank < 3.
Definition: triangulation.h:33
static SmartStereoProjectionParams params
traits
Definition: chartTesting.h:28
Point3 triangulateDLT(const std::vector< Matrix34, Eigen::aligned_allocator< Matrix34 >> &projection_matrices, const Point2Vector &measurements, double rank_tol)
Expression< Point2 > projection(f, p_cam)
float * p
static double error
Definition: testRot3.cpp:39
Vector3 Point3
Definition: Point3.h:35
VerbosityLM verbosityLM
The verbosity level for Levenberg-Marquardt (default: SILENT), see also NonlinearOptimizerParams::ver...
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
LinearSolverType linearSolverType
The type of linear solver to use in the nonlinear optimizer.
size_t maxIterations
The maximum iterations to stop iterating (default 100)
double lambdaInitial
The initial Levenberg-Marquardt damping term (default: 1e-5)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:16