timeSFMBALnavTcam.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 "timeSFMBAL.h"
20 
21 #include <gtsam/slam/expressions.h>
24 #include <gtsam/geometry/Point3.h>
25 
26 
27 using namespace std;
28 using namespace gtsam;
29 
30 int main(int argc, char* argv[]) {
31  // parse options and read BAL file
32  SfmData db = preamble(argc, argv);
33 
34  // Build graph using conventional GeneralSFMFactor
36  for (size_t j = 0; j < db.number_tracks(); j++) {
37  Point3_ nav_point_(P(j));
38  for (const SfmMeasurement& m: db.tracks[j].measurements) {
39  size_t i = m.first;
40  Point2 z = m.second;
41  Pose3_ navTcam_(C(i));
42  Cal3Bundler_ calibration_(K(i));
43  graph.addExpressionFactor(
44  gNoiseModel, z,
45  uncalibrate(calibration_,
46  project(transformTo(navTcam_, nav_point_))));
47  }
48  }
49 
51  size_t i = 0, j = 0;
52  for (const SfmCamera& camera: db.cameras) {
53  initial.insert(C(i), camera.pose());
54  initial.insert(K(i), camera.calibration());
55  i += 1;
56  }
57  for (const SfmTrack& track: db.tracks)
58  initial.insert(P(j++), track.p);
59 
60  bool separateCalibration = true;
61  return optimize(db, graph, initial, separateCalibration);
62 }
Matrix3f m
static Point2 project(const Pose3 &pose, const Unit3 &pointAtInfinity, const Cal3_S2::shared_ptr &cal)
const Pose3 & pose() const
return pose
static SharedNoiseModel gNoiseModel
Definition: timeSFMBAL.h:38
Define the structure for SfM data.
Definition: dataset.h:326
void insert(Key j, const Value &val)
Definition: Values.cpp:140
Vector2 Point2
Definition: Point2.h:27
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Values initial
Definition: Half.h:150
const Calibration & calibration() const override
return calibration
NonlinearFactorGraph graph
std::vector< SfmTrack > tracks
Sparse set of points.
Definition: dataset.h:328
Common code for timeSFMBAL scripts.
std::pair< size_t, Point2 > SfmMeasurement
A measurement with its camera index.
Definition: dataset.h:214
size_t number_tracks() const
The number of reconstructed 3D points.
Definition: dataset.h:333
Define the structure for the 3D points.
Definition: dataset.h:220
void addExpressionFactor(const SharedNoiseModel &R, const T &z, const Expression< T > &h)
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:37
traits
Definition: chartTesting.h:28
std::vector< SfmCamera > cameras
Set of cameras.
Definition: dataset.h:327
int main(int argc, char *argv[])
SfmData preamble(int argc, char *argv[])
Definition: timeSFMBAL.h:41
Point3 p
3D position of the point
Definition: dataset.h:224
3D Point
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
Definition: timeSFMBAL.h:63
Line3 transformTo(const Pose3 &wTc, const Line3 &wL, OptionalJacobian< 4, 6 > Dpose, OptionalJacobian< 4, 4 > Dline)
Definition: Line3.cpp:94
static const CalibratedCamera camera(kDefaultPose)
Calibration used by Bundler.
std::ptrdiff_t j
Point2 uncalibrate(const CAL &K, const Point2 &p, OptionalJacobian< 2, 5 > Dcal, OptionalJacobian< 2, 2 > Dp)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:50:54