| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file    timeSFMBAL.cpp | 
					
						
							| 
									
										
										
										
											2015-07-06 02:19:19 +08:00
										 |  |  |  * @brief   time SFM with BAL file,  conventional GeneralSFMFactor | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  * @date    June 6, 2015 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 01:26:11 +08:00
										 |  |  | #include "timeSFMBAL.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/slam/GeneralSFMFactor.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Cal3Bundler.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/PinholeCamera.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  | #include <gtsam/geometry/Point3.h>
 | 
					
						
							| 
									
										
										
										
											2015-06-09 08:01:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 10:43:26 +08:00
										 |  |  | typedef PinholeCamera<Cal3Bundler> Camera; | 
					
						
							|  |  |  | typedef GeneralSFMFactor<Camera, Point3> SfmFactor; | 
					
						
							| 
									
										
										
										
											2015-06-18 00:06:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 08:01:56 +08:00
										 |  |  | int main(int argc, char* argv[]) { | 
					
						
							| 
									
										
										
										
											2015-07-06 01:26:11 +08:00
										 |  |  |   // parse options and read BAL file
 | 
					
						
							| 
									
										
										
										
											2020-03-07 06:59:09 +08:00
										 |  |  |   SfmData db = preamble(argc, argv); | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 01:26:11 +08:00
										 |  |  |   // Build graph using conventional GeneralSFMFactor
 | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  |   NonlinearFactorGraph graph; | 
					
						
							| 
									
										
										
										
											2022-02-01 01:46:42 +08:00
										 |  |  |   for (size_t j = 0; j < db.numberTracks(); j++) { | 
					
						
							| 
									
										
										
										
											2020-03-07 06:59:09 +08:00
										 |  |  |     for (const SfmMeasurement& m: db.tracks[j].measurements) { | 
					
						
							| 
									
										
										
										
											2015-06-18 00:06:21 +08:00
										 |  |  |       size_t i = m.first; | 
					
						
							| 
									
										
										
										
											2015-07-05 06:54:46 +08:00
										 |  |  |       Point2 z = m.second; | 
					
						
							| 
									
										
										
										
											2016-10-01 23:17:41 +08:00
										 |  |  |       graph.emplace_shared<SfmFactor>(z, gNoiseModel, C(i), P(j)); | 
					
						
							| 
									
										
										
										
											2015-06-18 00:06:21 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 00:06:21 +08:00
										 |  |  |   Values initial; | 
					
						
							|  |  |  |   size_t i = 0, j = 0; | 
					
						
							| 
									
										
										
										
											2020-03-07 06:59:09 +08:00
										 |  |  |   for (const SfmCamera& camera: db.cameras) | 
					
						
							| 
									
										
										
										
											2015-07-06 01:26:11 +08:00
										 |  |  |     initial.insert(C(i++), camera); | 
					
						
							| 
									
										
										
										
											2020-03-07 06:59:09 +08:00
										 |  |  |   for (const SfmTrack& track: db.tracks) | 
					
						
							| 
									
										
										
										
											2015-06-18 00:06:21 +08:00
										 |  |  |     initial.insert(P(j++), track.p); | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 01:26:11 +08:00
										 |  |  |   return optimize(db, graph, initial); | 
					
						
							| 
									
										
										
										
											2015-06-08 11:53:54 +08:00
										 |  |  | } |