timeSFMBALnavTcam.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* ----------------------------------------------------------------------------
  2. * GTSAM Copyright 2010, Georgia Tech Research Corporation,
  3. * Atlanta, Georgia 30332-0415
  4. * All Rights Reserved
  5. * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. * -------------------------------------------------------------------------- */
  8. /**
  9. * @file timeSFMBALnavTcam.cpp
  10. * @brief time SFM with BAL file, expressions with navTcam pose
  11. * @author Frank Dellaert
  12. * @date July 5, 2015
  13. */
  14. #include "timeSFMBAL.h"
  15. #include <gtsam/slam/expressions.h>
  16. #include <gtsam/nonlinear/ExpressionFactor.h>
  17. #include <gtsam/geometry/Cal3Bundler.h>
  18. #include <gtsam/geometry/Point3.h>
  19. using namespace std;
  20. using namespace gtsam;
  21. int main(int argc, char* argv[]) {
  22. // parse options and read BAL file
  23. SfmData db = preamble(argc, argv);
  24. // Build graph using conventional GeneralSFMFactor
  25. NonlinearFactorGraph graph;
  26. for (size_t j = 0; j < db.number_tracks(); j++) {
  27. Point3_ nav_point_(P(j));
  28. for (const SfmMeasurement& m: db.tracks[j].measurements) {
  29. size_t i = m.first;
  30. Point2 z = m.second;
  31. Pose3_ navTcam_(C(i));
  32. Cal3Bundler_ calibration_(K(i));
  33. graph.addExpressionFactor(
  34. gNoiseModel, z,
  35. uncalibrate(calibration_,
  36. project(transformTo(navTcam_, nav_point_))));
  37. }
  38. }
  39. Values initial;
  40. size_t i = 0, j = 0;
  41. for (const SfmCamera& camera: db.cameras) {
  42. initial.insert(C(i), camera.pose());
  43. initial.insert(K(i), camera.calibration());
  44. i += 1;
  45. }
  46. for (const SfmTrack& track: db.tracks)
  47. initial.insert(P(j++), track.p);
  48. bool separateCalibration = true;
  49. return optimize(db, graph, initial, separateCalibration);
  50. }