CameraResectioning.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 
19 #include <gtsam/inference/Symbol.h>
22 #include <gtsam/geometry/Cal3_S2.h>
23 #include <boost/make_shared.hpp>
24 
25 using namespace gtsam;
26 using namespace gtsam::noiseModel;
28 
33 class ResectioningFactor: public NoiseModelFactor1<Pose3> {
35 
39 
40 public:
41 
44  const Cal3_S2::shared_ptr& calib, const Point2& p, const Point3& P) :
45  Base(model, key), K_(calib), P_(P), p_(p) {
46  }
47 
49  Vector evaluateError(const Pose3& pose, boost::optional<Matrix&> H =
50  boost::none) const override {
51  PinholeCamera<Cal3_S2> camera(pose, *K_);
52  return camera.project(P_, H, boost::none, boost::none) - p_;
53  }
54 };
55 
56 /*******************************************************************************
57  * Camera: f = 1, Image: 100x100, center: 50, 50.0
58  * Pose (ground truth): (Xw, -Yw, -Zw, [0,0,2.0]')
59  * Known landmarks:
60  * 3D Points: (10,10,0) (-10,10,0) (-10,-10,0) (10,-10,0)
61  * Perfect measurements:
62  * 2D Point: (55,45) (45,45) (45,55) (55,55)
63  *******************************************************************************/
64 int main(int argc, char* argv[]) {
65  /* read camera intrinsic parameters */
66  Cal3_S2::shared_ptr calib(new Cal3_S2(1, 1, 0, 50, 50));
67 
68  /* 1. create graph */
70 
71  /* 2. add factors to the graph */
72  // add measurement factors
73  SharedDiagonal measurementNoise = Diagonal::Sigmas(Vector2(0.5, 0.5));
74  boost::shared_ptr<ResectioningFactor> factor;
75  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
76  Point2(55, 45), Point3(10, 10, 0));
77  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
78  Point2(45, 45), Point3(-10, 10, 0));
79  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
80  Point2(45, 55), Point3(-10, -10, 0));
81  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
82  Point2(55, 55), Point3(10, -10, 0));
83 
84  /* 3. Create an initial estimate for the camera pose */
86  initial.insert(X(1),
87  Pose3(Rot3(1, 0, 0, 0, -1, 0, 0, 0, -1), Point3(0, 0, 2)));
88 
89  /* 4. Optimize the graph using Levenberg-Marquardt*/
91  result.print("Final result:\n");
92 
93  return 0;
94 }
int main(int argc, char *argv[])
virtual const Values & optimize()
Cal3_S2::shared_ptr K_
camera&#39;s intrinsic parameters
NoiseModelFactor1< Pose3 > Base
noiseModel::Diagonal::shared_ptr model
void insert(Key j, const Value &val)
Definition: Values.cpp:140
Vector2 Point2
Definition: Point2.h:27
Values initial
Point2 p_
2D measurement of the 3D point
Key X(std::uint64_t j)
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 y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
NonlinearFactorGraph graph
Base class for all pinhole cameras.
Vector evaluateError(const Pose3 &pose, boost::optional< Matrix & > H=boost::none) const override
evaluate the error
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:172
Eigen::VectorXd Vector
Definition: Vector.h:38
Values result
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:736
traits
Definition: chartTesting.h:28
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Definition: Values.cpp:77
Eigen::Vector2d Vector2
Definition: Vector.h:42
ResectioningFactor(const SharedNoiseModel &model, const Key &key, const Cal3_S2::shared_ptr &calib, const Point2 &p, const Point3 &P)
Construct factor given known point P and its projection p.
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
Definition: NoiseModel.cpp:270
Point3 P_
3D point on the calibration rig
float * p
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
Definition: PinholePose.h:118
Vector3 Point3
Definition: Point3.h:35
static const CalibratedCamera camera(kDefaultPose)
#define X
Definition: icosphere.cpp:20
boost::shared_ptr< Cal3_S2 > shared_ptr
Definition: Cal3_S2.h:39
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
The most common 5DOF 3D->2D calibration.
All noise models live in the noiseModel namespace.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:45