| 22 | } |
| 23 | |
| 24 | bool GlobalPositioner::Solve(const ViewGraph& view_graph, |
| 25 | std::unordered_map<camera_t, Camera>& cameras, |
| 26 | std::unordered_map<image_t, Image>& images, |
| 27 | std::unordered_map<track_t, Track>& tracks) { |
| 28 | if (images.empty()) { |
| 29 | LOG(ERROR) << "Number of images = " << images.size(); |
| 30 | return false; |
| 31 | } |
| 32 | if (view_graph.image_pairs.empty() && |
| 33 | options_.constraint_type != GlobalPositionerOptions::ONLY_POINTS) { |
| 34 | LOG(ERROR) << "Number of image_pairs = " << view_graph.image_pairs.size(); |
| 35 | return false; |
| 36 | } |
| 37 | if (tracks.empty() && |
| 38 | options_.constraint_type != GlobalPositionerOptions::ONLY_CAMERAS) { |
| 39 | LOG(ERROR) << "Number of tracks = " << tracks.size(); |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | LOG(INFO) << "Setting up the global positioner problem"; |
| 44 | |
| 45 | // Setup the problem. |
| 46 | SetupProblem(view_graph, tracks); |
| 47 | |
| 48 | // Initialize camera translations to be random. |
| 49 | // Also, convert the camera pose translation to be the camera center. |
| 50 | InitializeRandomPositions(view_graph, images, tracks); |
| 51 | |
| 52 | // Add the camera to camera constraints to the problem. |
| 53 | if (options_.constraint_type != GlobalPositionerOptions::ONLY_POINTS) { |
| 54 | AddCameraToCameraConstraints(view_graph, images); |
| 55 | } |
| 56 | |
| 57 | // Add the point to camera constraints to the problem. |
| 58 | if (options_.constraint_type != GlobalPositionerOptions::ONLY_CAMERAS) { |
| 59 | AddPointToCameraConstraints(cameras, images, tracks); |
| 60 | } |
| 61 | |
| 62 | AddCamerasAndPointsToParameterGroups(images, tracks); |
| 63 | |
| 64 | // Parameterize the variables, set image poses / tracks / scales to be |
| 65 | // constant if desired |
| 66 | ParameterizeVariables(images, tracks); |
| 67 | |
| 68 | LOG(INFO) << "Solving the global positioner problem"; |
| 69 | |
| 70 | ceres::Solver::Summary summary; |
| 71 | options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2); |
| 72 | ceres::Solve(options_.solver_options, problem_.get(), &summary); |
| 73 | |
| 74 | if (VLOG_IS_ON(2)) { |
| 75 | LOG(INFO) << summary.FullReport(); |
| 76 | } else { |
| 77 | LOG(INFO) << summary.BriefReport(); |
| 78 | } |
| 79 | |
| 80 | ConvertResults(images); |
| 81 | return summary.IsSolutionUsable(); |
nothing calls this directly
no outgoing calls
no test coverage detected