2 GTSAM Copyright 2010, Georgia Tech Research Corporation, 3 Atlanta, Georgia 30332-0415 5 Authors: Frank Dellaert, et al. (see THANKS for the full author list) 7 See LICENSE for the license information 9 Solve a structure-from-motion problem from a "Bundle Adjustment in the Large" file 10 Author: Frank Dellaert (Python: Akshay Krishnan, John Lambert) 17 import matplotlib.pyplot
as plt
22 GeneralSFMFactorCal3Bundler,
23 PinholeCameraCal3Bundler,
24 PriorFactorPinholeCameraCal3Bundler,
29 C = symbol_shorthand.C
30 P = symbol_shorthand.P
33 logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
36 """ Run LM optimization with BAL input data and report resulting error """ 40 scene_data =
readBal(input_file)
41 logging.info(f
"read {scene_data.number_tracks()} tracks on {scene_data.number_cameras()} cameras\n")
51 for t_idx
in range(scene_data.number_tracks()):
52 track = scene_data.track(t_idx)
54 for m_idx
in range(track.number_measurements()):
56 i, uv = track.measurement(m_idx)
63 gtsam.PriorFactorPinholeCameraCal3Bundler(
69 gtsam.PriorFactorPoint3(
79 for cam_idx
in range(scene_data.number_cameras()):
80 camera = scene_data.camera(cam_idx)
81 initial.insert(C(i), camera)
86 for t_idx
in range(scene_data.number_tracks()):
87 track = scene_data.track(t_idx)
88 initial.insert(
P(j), track.point3())
94 params.setVerbosityLM(
"ERROR")
96 result = lm.optimize()
97 except Exception
as e:
98 logging.exception(
"LM Optimization failed")
101 logging.info(f
"final error: {graph.error(result)}")
104 if __name__ ==
"__main__":
105 parser = argparse.ArgumentParser()
110 default=
"dubrovnik-3-7-pre",
111 help=
'Read SFM data from the specified BAL file' 112 'The data format is described here: https://grail.cs.washington.edu/projects/bal/.' 113 'BAL files contain (nrPoses, nrPoints, nrObservations), followed by (i,j,u,v) tuples, ' 114 'then (wx,wy,wz,tx,ty,tz,f,k1,k1) as Bundler camera calibrations w/ Rodrigues vector' 115 'and (x,y,z) 3d point initializations.' 117 run(parser.parse_args())
SfmData readBal(const string &filename)
This function parses a "Bundle Adjustment in the Large" (BAL) file and returns the data as a SfmData ...
static const Point3 point3(0.08, 0.08, 0.0)
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)