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.numberTracks(); 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)
static SharedNoiseModel gNoiseModel
Definition: timeSFMBAL.h:41
SfmData stores a bunch of SfmTracks.
Definition: SfmData.h:39
Vector2 Point2
Definition: Point2.h:32
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Values initial
Definition: BFloat16.h:88
const Calibration & calibration() const override
return calibration
NonlinearFactorGraph graph
std::vector< SfmTrack > tracks
Sparse set of points.
Definition: SfmData.h:42
const Pose3 & pose() const
return pose
Common code for timeSFMBAL scripts.
std::pair< size_t, Point2 > SfmMeasurement
A measurement with its camera index.
Definition: SfmTrack.h:32
void addExpressionFactor(const SharedNoiseModel &R, const T &z, const Expression< T > &h)
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
traits
Definition: chartTesting.h:28
std::vector< SfmCamera > cameras
Set of cameras.
Definition: SfmData.h:40
int main(int argc, char *argv[])
SfmData preamble(int argc, char *argv[])
Definition: timeSFMBAL.h:44
Point3 p
3D position of the point
Definition: SfmTrack.h:126
3D Point
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
Definition: timeSFMBAL.h:64
void insert(Key j, const Value &val)
Definition: Values.cpp:155
Line3 transformTo(const Pose3 &wTc, const Line3 &wL, OptionalJacobian< 4, 6 > Dpose, OptionalJacobian< 4, 4 > Dline)
Definition: Line3.cpp:94
size_t numberTracks() const
The number of reconstructed 3D points.
Definition: SfmData.h:74
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 Tue Jul 4 2023 02:40:14