36 std::runtime_error(
"Triangulation Underconstrained Exception.") {
45 "Triangulation Cheirality Exception: The resulting landmark is behind one or more cameras.") {
70 double rank_tol = 1
e-9);
81 template<
class CALIBRATION>
83 const std::vector<Pose3>& poses, boost::shared_ptr<CALIBRATION>
sharedCal,
85 const Point3& initialEstimate) {
87 values.
insert(landmarkKey, initialEstimate);
91 for (
size_t i = 0;
i < measurements.size();
i++) {
92 const Pose3& pose_i = poses[
i];
94 Camera camera_i(pose_i, sharedCal);
96 (camera_i, measurements[
i],
unit2, landmarkKey);
98 return std::make_pair(graph, values);
110 template<
class CAMERA>
113 const typename CAMERA::MeasurementVector& measurements,
Key landmarkKey,
114 const Point3& initialEstimate) {
116 values.
insert(landmarkKey, initialEstimate);
120 for (
size_t i = 0;
i < measurements.size();
i++) {
121 const CAMERA& camera_i = cameras[
i];
123 (camera_i, measurements[
i], unit, landmarkKey);
125 return std::make_pair(graph, values);
146 template<
class CALIBRATION>
148 boost::shared_ptr<CALIBRATION>
sharedCal,
154 boost::tie(graph, values) = triangulationGraph<CALIBRATION>
167 template<
class CAMERA>
170 const typename CAMERA::MeasurementVector& measurements,
const Point3& initialEstimate) {
175 boost::tie(graph, values) = triangulationGraph<CAMERA>
176 (cameras, measurements,
Symbol(
'p', 0), initialEstimate);
188 template<
class CALIBRATION>
191 K_(calibration.
K()) {
214 template<
class CALIBRATION>
216 boost::shared_ptr<CALIBRATION>
sharedCal,
218 bool optimize =
false) {
220 assert(poses.size() == measurements.size());
221 if (poses.size() < 2)
225 std::vector<Matrix34, Eigen::aligned_allocator<Matrix34>> projection_matrices;
228 projection_matrices.push_back(createP(
pose));
235 point = triangulateNonlinear<CALIBRATION>
238 #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION 241 const Point3& p_local =
pose.transformTo(point);
242 if (p_local.z() <= 0)
262 template<
class CAMERA>
265 const typename CAMERA::MeasurementVector& measurements,
double rank_tol = 1
e-9,
266 bool optimize =
false) {
268 size_t m = cameras.size();
269 assert(measurements.size() ==
m);
275 std::vector<Matrix34, Eigen::aligned_allocator<Matrix34>> projection_matrices;
276 for(
const CAMERA&
camera: cameras)
277 projection_matrices.push_back(
284 point = triangulateNonlinear<CAMERA>(cameras, measurements,
point);
286 #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION 288 for(
const CAMERA&
camera: cameras) {
289 const Point3& p_local =
camera.pose().transformTo(point);
290 if (p_local.z() <= 0)
299 template<
class CALIBRATION>
303 bool optimize =
false) {
304 return triangulatePoint3<PinholeCamera<CALIBRATION> >
305 (cameras, measurements, rank_tol,
optimize);
336 const bool _enableEPI =
false,
double _landmarkDistanceThreshold = -1,
337 double _dynamicOutlierRejectionThreshold = -1) :
338 rankTolerance(_rankTolerance), enableEPI(_enableEPI),
339 landmarkDistanceThreshold(_landmarkDistanceThreshold),
340 dynamicOutlierRejectionThreshold(_dynamicOutlierRejectionThreshold) {
347 os <<
"enableEPI = " << p.
enableEPI << std::endl;
350 os <<
"dynamicOutlierRejectionThreshold = " 358 friend class boost::serialization::access;
359 template<
class ARCHIVE>
361 ar & BOOST_SERIALIZATION_NVP(rankTolerance);
362 ar & BOOST_SERIALIZATION_NVP(enableEPI);
363 ar & BOOST_SERIALIZATION_NVP(landmarkDistanceThreshold);
364 ar & BOOST_SERIALIZATION_NVP(dynamicOutlierRejectionThreshold);
373 VALID, DEGENERATE, BEHIND_CAMERA, OUTLIER, FAR_POINT
406 return status_ == VALID;
409 return status_ == DEGENERATE;
412 return status_ == OUTLIER;
415 return status_ == FAR_POINT;
418 return status_ == BEHIND_CAMERA;
424 os <<
"point = " << *result << std::endl;
426 os <<
"no point, status = " << result.
status_ << std::endl;
433 friend class boost::serialization::access;
434 template<
class ARCHIVE>
436 ar & BOOST_SERIALIZATION_NVP(status_);
441 template<
class CAMERA>
443 const typename CAMERA::MeasurementVector&
measured,
446 size_t m = cameras.size();
459 double maxReprojError = 0.0;
460 for(
const CAMERA&
camera: cameras) {
466 #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION 470 if (p_local.z() <= 0)
475 const Point2& zi = measured.at(i);
477 maxReprojError =
std::max(maxReprojError, reprojectionError.norm());
Vector4 triangulateHomogeneousDLT(const std::vector< Matrix34, Eigen::aligned_allocator< Matrix34 >> &projection_matrices, const Point2Vector &measurements, double rank_tol)
TriangulationResult(Status s)
TriangulationResult(const Point3 &p)
bool behindCamera() const
static TriangulationResult Outlier()
Factor Graph consisting of non-linear factors.
void insert(Key j, const Value &val)
Base class to create smart factors on poses or cameras.
PinholeCamera< Cal3Bundler0 > Camera
double dynamicOutlierRejectionThreshold
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Point3 triangulateNonlinear(const std::vector< Pose3 > &poses, boost::shared_ptr< CALIBRATION > sharedCal, const Point2Vector &measurements, const Point3 &initialEstimate)
const Point3 & translation(OptionalJacobian< 3, 6 > Hself=boost::none) const
get translation
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
static const boost::shared_ptr< Cal3_S2 > sharedCal
static TriangulationResult BehindCamera()
static shared_ptr Create(size_t dim)
double distance3(const Point3 &p1, const Point3 &q, OptionalJacobian< 1, 3 > H1, OptionalJacobian< 1, 3 > H2)
distance between two points
TriangulationUnderconstrainedException()
friend std::ostream & operator<<(std::ostream &os, const TriangulationResult &result)
TriangulationParameters(const double _rankTolerance=1.0, const bool _enableEPI=false, double _landmarkDistanceThreshold=-1, double _dynamicOutlierRejectionThreshold=-1)
Base class for all pinhole cameras.
Point3 transformTo(const Point3 &point, OptionalJacobian< 3, 6 > Hself=boost::none, OptionalJacobian< 3, 3 > Hpoint=boost::none) const
takes point in world coordinates and transforms it to Pose coordinates
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
double landmarkDistanceThreshold
Pose3 inverse() const
inverse transformation with derivatives
Point3 triangulatePoint3(const std::vector< Pose3 > &poses, boost::shared_ptr< CALIBRATION > sharedCal, const Point2Vector &measurements, double rank_tol=1e-9, bool optimize=false)
STL compatible allocator to use with types requiring a non standrad alignment.
void serialize(ARCHIVE &ar, const unsigned int version)
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
bool enableEPI
if set to true, will refine triangulation using LM
double rankTolerance
(the rank is the number of singular values of the triangulation matrix which are larger than rankTole...
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
Matrix34 operator()(const Pose3 &pose) const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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
void serialize(ARCHIVE &ar, const unsigned int version)
Exception thrown by triangulateDLT when landmark is behind one or more of the cameras.
static TriangulationResult FarPoint()
static SharedNoiseModel unit2(noiseModel::Unit::Create(2))
friend std::ostream & operator<<(std::ostream &os, const TriangulationParameters &p)
std::pair< NonlinearFactorGraph, Values > triangulationGraph(const std::vector< Pose3 > &poses, boost::shared_ptr< CALIBRATION > sharedCal, const Point2Vector &measurements, Key landmarkKey, const Point3 &initialEstimate)
ofstream os("timeSchurFactors.csv")
Point3 triangulateDLT(const std::vector< Matrix34, Eigen::aligned_allocator< Matrix34 >> &projection_matrices, const Point2Vector &measurements, double rank_tol)
static TriangulationResult Degenerate()
CameraProjectionMatrix(const CALIBRATION &calibration)
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW
TriangulationCheiralityException()
static const CalibratedCamera camera(kDefaultPose)
std::uint64_t Key
Integer nonlinear key type.
Calibration used by Bundler.
noiseModel::Base::shared_ptr SharedNoiseModel
The most common 5DOF 3D->2D calibration.
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)