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 
24 using namespace gtsam;
25 using namespace gtsam::noiseModel;
27 
32 class ResectioningFactor: public NoiseModelFactorN<Pose3> {
34 
38 
39 public:
40 
43  const Cal3_S2::shared_ptr& calib, const Point2& p, const Point3& P) :
44  Base(model, key), K_(calib), P_(P), p_(p) {
45  }
46 
48  Vector evaluateError(const Pose3& pose, OptionalMatrixType H) const override {
50  return camera.project(P_, H, OptionalNone, OptionalNone) - p_;
51  }
52 };
53 
54 /*******************************************************************************
55  * Camera: f = 1, Image: 100x100, center: 50, 50.0
56  * Pose (ground truth): (Xw, -Yw, -Zw, [0,0,2.0]')
57  * Known landmarks:
58  * 3D Points: (10,10,0) (-10,10,0) (-10,-10,0) (10,-10,0)
59  * Perfect measurements:
60  * 2D Point: (55,45) (45,45) (45,55) (55,55)
61  *******************************************************************************/
62 int main(int argc, char* argv[]) {
63  /* read camera intrinsic parameters */
64  Cal3_S2::shared_ptr calib(new Cal3_S2(1, 1, 0, 50, 50));
65 
66  /* 1. create graph */
68 
69  /* 2. add factors to the graph */
70  // add measurement factors
71  SharedDiagonal measurementNoise = Diagonal::Sigmas(Vector2(0.5, 0.5));
72  std::shared_ptr<ResectioningFactor> factor;
73  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
74  Point2(55, 45), Point3(10, 10, 0));
75  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
76  Point2(45, 45), Point3(-10, 10, 0));
77  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
78  Point2(45, 55), Point3(-10, -10, 0));
79  graph.emplace_shared<ResectioningFactor>(measurementNoise, X(1), calib,
80  Point2(55, 55), Point3(10, -10, 0));
81 
82  /* 3. Create an initial estimate for the camera pose */
84  initial.insert(X(1),
85  Pose3(Rot3(1, 0, 0, 0, -1, 0, 0, 0, -1), Point3(0, 0, 2)));
86 
87  /* 4. Optimize the graph using Levenberg-Marquardt*/
89  result.print("Final result:\n");
90 
91  return 0;
92 }
H
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
Definition: gnuplot_common_settings.hh:74
gtsam::NonlinearOptimizer::optimize
virtual const Values & optimize()
Definition: NonlinearOptimizer.h:98
pose
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
gtsam::Vector2
Eigen::Vector2d Vector2
Definition: Vector.h:42
Cal3_S2.h
The most common 5DOF 3D->2D calibration.
LevenbergMarquardtOptimizer.h
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
initial
Values initial
Definition: OdometryOptimize.cpp:2
ResectioningFactor::Base
NoiseModelFactorN< Pose3 > Base
Definition: CameraResectioning.cpp:33
ResectioningFactor::P_
Point3 P_
3D point on the calibration rig
Definition: CameraResectioning.cpp:36
gtsam::noiseModel::Diagonal::Sigmas
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
Definition: NoiseModel.cpp:291
X
#define X
Definition: icosphere.cpp:20
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::symbol_shorthand::X
Key X(std::uint64_t j)
Definition: inference/Symbol.h:171
OptionalNone
#define OptionalNone
Definition: NonlinearFactor.h:49
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
ResectioningFactor::p_
Point2 p_
2D measurement of the 3D point
Definition: CameraResectioning.cpp:37
gtsam::Pose3
Definition: Pose3.h:37
gtsam::PinholeCamera
Definition: PinholeCamera.h:33
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:431
gtsam::SharedDiagonal
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:764
PinholeCamera.h
Base class for all pinhole cameras.
ResectioningFactor::K_
Cal3_S2::shared_ptr K_
camera's intrinsic parameters
Definition: CameraResectioning.cpp:35
gtsam::LevenbergMarquardtOptimizer
Definition: LevenbergMarquardtOptimizer.h:35
Symbol.h
ResectioningFactor::ResectioningFactor
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.
Definition: CameraResectioning.cpp:42
gtsam::Point2
Vector2 Point2
Definition: Point2.h:32
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::Cal3_S2::shared_ptr
std::shared_ptr< Cal3_S2 > shared_ptr
Definition: Cal3_S2.h:39
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
key
const gtsam::Symbol key('X', 0)
gtsam::Values::print
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Definition: Values.cpp:66
gtsam
traits
Definition: SFMdata.h:40
gtsam::Values
Definition: Values.h:65
gtsam::noiseModel
All noise models live in the noiseModel namespace.
Definition: LossFunctions.cpp:28
p
float * p
Definition: Tutorial_Map_using.cpp:9
main
int main(int argc, char *argv[])
Definition: CameraResectioning.cpp:62
P
static double P[]
Definition: ellpe.c:68
ResectioningFactor::evaluateError
Vector evaluateError(const Pose3 &pose, OptionalMatrixType H) const override
evaluate the error
Definition: CameraResectioning.cpp:48
gtsam::Cal3_S2
The most common 5DOF 3D->2D calibration.
Definition: Cal3_S2.h:34
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
initial
Definition: testScenarioRunner.cpp:148
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
camera
static const CalibratedCamera camera(kDefaultPose)
ResectioningFactor
Definition: CameraResectioning.cpp:32
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::CalibratedCamera::project
Point2 project(const Point3 &point, OptionalJacobian< 2, 6 > Dcamera={}, OptionalJacobian< 2, 3 > Dpoint={}) const
Definition: CalibratedCamera.cpp:188
gtsam::FactorGraph::emplace_shared
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:153


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:57