| 15 | namespace glomap { |
| 16 | |
| 17 | bool GlobalMapper::Solve(const colmap::Database& database, |
| 18 | ViewGraph& view_graph, |
| 19 | std::unordered_map<camera_t, Camera>& cameras, |
| 20 | std::unordered_map<image_t, Image>& images, |
| 21 | std::unordered_map<track_t, Track>& tracks) { |
| 22 | // 0. Preprocessing |
| 23 | if (!options_.skip_preprocessing) { |
| 24 | std::cout << "-------------------------------------" << std::endl; |
| 25 | std::cout << "Running preprocessing ..." << std::endl; |
| 26 | std::cout << "-------------------------------------" << std::endl; |
| 27 | |
| 28 | colmap::Timer run_timer; |
| 29 | run_timer.Start(); |
| 30 | // If camera intrinsics seem to be good, force the pair to use essential |
| 31 | // matrix |
| 32 | ViewGraphManipulater::UpdateImagePairsConfig(view_graph, cameras, images); |
| 33 | ViewGraphManipulater::DecomposeRelPose(view_graph, cameras, images); |
| 34 | run_timer.PrintSeconds(); |
| 35 | } |
| 36 | |
| 37 | // 1. Run view graph calibration |
| 38 | if (!options_.skip_view_graph_calibration) { |
| 39 | std::cout << "-------------------------------------" << std::endl; |
| 40 | std::cout << "Running view graph calibration ..." << std::endl; |
| 41 | std::cout << "-------------------------------------" << std::endl; |
| 42 | ViewGraphCalibrator vgcalib_engine(options_.opt_vgcalib); |
| 43 | if (!vgcalib_engine.Solve(view_graph, cameras, images)) { |
| 44 | return false; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // 2. Run relative pose estimation |
| 49 | if (!options_.skip_relative_pose_estimation) { |
| 50 | std::cout << "-------------------------------------" << std::endl; |
| 51 | std::cout << "Running relative pose estimation ..." << std::endl; |
| 52 | std::cout << "-------------------------------------" << std::endl; |
| 53 | |
| 54 | colmap::Timer run_timer; |
| 55 | run_timer.Start(); |
| 56 | // Relative pose relies on the undistorted images |
| 57 | UndistortImages(cameras, images, true); |
| 58 | EstimateRelativePoses(view_graph, cameras, images, options_.opt_relpose); |
| 59 | |
| 60 | InlierThresholdOptions inlier_thresholds = options_.inlier_thresholds; |
| 61 | // Undistort the images and filter edges by inlier number |
| 62 | ImagePairsInlierCount(view_graph, cameras, images, inlier_thresholds, true); |
| 63 | |
| 64 | RelPoseFilter::FilterInlierNum(view_graph, |
| 65 | options_.inlier_thresholds.min_inlier_num); |
| 66 | RelPoseFilter::FilterInlierRatio( |
| 67 | view_graph, options_.inlier_thresholds.min_inlier_ratio); |
| 68 | |
| 69 | if (view_graph.KeepLargestConnectedComponents(images) == 0) { |
| 70 | LOG(ERROR) << "no connected components are found"; |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | run_timer.PrintSeconds(); |