SfmData.h
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 #pragma once
20 
24 #include <gtsam/nonlinear/Values.h>
25 #include <gtsam/sfm/SfmTrack.h>
26 
27 #include <string>
28 #include <vector>
29 
30 namespace gtsam {
31 
34 
39 struct GTSAM_EXPORT SfmData {
40  std::vector<SfmCamera> cameras;
41 
42  std::vector<SfmTrack> tracks;
43 
46 
53  static SfmData FromBundlerFile(const std::string& filename);
54 
61  static SfmData FromBalFile(const std::string& filename);
62 
66 
68  void addTrack(const SfmTrack& t) { tracks.push_back(t); }
69 
71  void addCamera(const SfmCamera& cam) { cameras.push_back(cam); }
72 
74  size_t numberTracks() const { return tracks.size(); }
75 
77  size_t numberCameras() const { return cameras.size(); }
78 
80  const SfmTrack& track(size_t idx) const { return tracks[idx]; }
81 
83  const SfmCamera& camera(size_t idx) const { return cameras[idx]; }
84 
86  const std::vector<SfmCamera>& cameraList() const { return cameras; }
87  const std::vector<SfmTrack>& trackList() const { return tracks; }
88 
95  NonlinearFactorGraph generalSfmFactors(
97  1.0)) const;
98 
109  NonlinearFactorGraph sfmFactorGraph(
111  std::optional<size_t> fixedCamera = 0,
112  std::optional<size_t> fixedPoint = 0) const;
113 
117 
119  void print(const std::string& s = "") const;
120 
122  bool equals(const SfmData& sfmData, double tol = 1e-9) const;
123 
127 
128 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
129  friend class boost::serialization::access;
131  template <class Archive>
132  void serialize(Archive& ar, const unsigned int /*version*/) {
133  ar& BOOST_SERIALIZATION_NVP(cameras);
134  ar& BOOST_SERIALIZATION_NVP(tracks);
135  }
136 #endif
137 
138 
140 };
141 
143 template <>
144 struct traits<SfmData> : public Testable<SfmData> {};
145 
152 GTSAM_EXPORT SfmData readBal(const std::string& filename);
153 
161 GTSAM_EXPORT bool writeBAL(const std::string& filename, const SfmData& data);
162 
175 GTSAM_EXPORT bool writeBALfromValues(const std::string& filename,
176  const SfmData& data, const Values& values);
177 
186 GTSAM_EXPORT Pose3 openGL2gtsam(const Rot3& R, double tx, double ty, double tz);
187 
196 GTSAM_EXPORT Pose3 gtsam2openGL(const Rot3& R, double tx, double ty, double tz);
197 
203 GTSAM_EXPORT Pose3 gtsam2openGL(const Pose3& PoseGTSAM);
204 
213 GTSAM_EXPORT Values initialCamerasEstimate(const SfmData& db);
214 
223 GTSAM_EXPORT Values initialCamerasAndPointsEstimate(const SfmData& db);
224 
225 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
SfmData readBal(const std::string &filename)
This function parses a "Bundle Adjustment in the Large" (BAL) file and returns the data as a SfmData ...
Definition: SfmData.cpp:325
const SfmCamera & camera(size_t idx) const
The camera pose at frame index idx
Definition: SfmData.h:83
void addTrack(const SfmTrack &t)
Add a track to SfmData.
Definition: SfmData.h:68
SfmData stores a bunch of SfmTracks.
Definition: SfmData.h:39
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
std::string serialize(const T &input)
serializes to a string
noiseModel::Diagonal::shared_ptr model
A simple data structure for a track in Structure from Motion.
Rot2 R(Rot2::fromAngle(0.1))
leaf::MyValues values
Values initialCamerasAndPointsEstimate(const SfmData &db)
This function creates initial values for cameras and points from db.
Definition: SfmData.cpp:430
const SfmTrack & track(size_t idx) const
The track formed by series of landmark measurements.
Definition: SfmData.h:80
Pose3 openGL2gtsam(const Rot3 &R, double tx, double ty, double tz)
This function converts an openGL camera pose to an GTSAM camera pose.
Definition: SfmData.cpp:79
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
std::vector< SfmTrack > tracks
Sparse set of points.
Definition: SfmData.h:42
Base class for all pinhole cameras.
bool writeBALfromValues(const std::string &filename, const SfmData &data, const Values &values)
This function writes a "Bundle Adjustment in the Large" (BAL) file from a SfmData structure and a val...
Definition: SfmData.cpp:330
int data[]
size_t numberCameras() const
The number of cameras.
Definition: SfmData.h:77
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
const std::vector< SfmCamera > & cameraList() const
Getters.
Definition: SfmData.h:86
Values initialCamerasEstimate(const SfmData &db)
This function creates initial values for cameras from db.
Definition: SfmData.cpp:422
const std::vector< SfmTrack > & trackList() const
Definition: SfmData.h:87
traits
Definition: chartTesting.h:28
void addCamera(const SfmCamera &cam)
Add a camera to SfmData.
Definition: SfmData.h:71
std::vector< SfmCamera > cameras
Set of cameras.
Definition: SfmData.h:40
PinholeCamera< Cal3Bundler > SfmCamera
Define the structure for the camera poses.
Definition: SfmData.h:33
size_t numberTracks() const
The number of reconstructed 3D points.
Definition: SfmData.h:74
const G double tol
Definition: Group.h:86
Pose3 gtsam2openGL(const Rot3 &R, double tx, double ty, double tz)
This function converts a GTSAM camera pose to an openGL camera pose.
Definition: SfmData.cpp:88
Calibration used by Bundler.
bool writeBAL(const std::string &filename, const SfmData &data)
This function writes a "Bundle Adjustment in the Large" (BAL) file from a SfmData structure...
Definition: SfmData.cpp:249
Point2 t(10, 10)
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
Definition: NoiseModel.cpp:594


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:42