| 307 | } |
| 308 | |
| 309 | std::vector<image_t> IncrementalMapperImpl::FindNextImages( |
| 310 | const IncrementalMapper::Options& options, |
| 311 | const ObservationManager& obs_manager, |
| 312 | const std::unordered_set<frame_t>& filtered_frames, |
| 313 | std::unordered_map<image_t, size_t>& num_reg_trials, |
| 314 | bool structure_less) { |
| 315 | THROW_CHECK(options.Check()); |
| 316 | const Reconstruction& reconstruction = obs_manager.Reconstruction(); |
| 317 | |
| 318 | std::function<float(image_t, const ObservationManager&)> rank_image_func; |
| 319 | if (structure_less) { |
| 320 | rank_image_func = [](image_t image_id, |
| 321 | const ObservationManager& obs_manager) { |
| 322 | return static_cast<float>( |
| 323 | obs_manager.NumVisibleCorrespondences(image_id)); |
| 324 | }; |
| 325 | } else { |
| 326 | switch (options.image_selection_method) { |
| 327 | case IncrementalMapper::Options::ImageSelectionMethod:: |
| 328 | MAX_VISIBLE_POINTS_NUM: |
| 329 | rank_image_func = RankNextImageMaxVisiblePointsNum; |
| 330 | break; |
| 331 | case IncrementalMapper::Options::ImageSelectionMethod:: |
| 332 | MAX_VISIBLE_POINTS_RATIO: |
| 333 | rank_image_func = RankNextImageMaxVisiblePointsRatio; |
| 334 | break; |
| 335 | case IncrementalMapper::Options::ImageSelectionMethod::MIN_UNCERTAINTY: |
| 336 | rank_image_func = RankNextImageMinUncertainty; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | std::vector<std::pair<image_t, float>> image_ranks; |
| 342 | std::vector<std::pair<image_t, float>> other_image_ranks; |
| 343 | |
| 344 | // Append images that have not failed to register before. |
| 345 | for (const auto& [image_id, image] : reconstruction.Images()) { |
| 346 | // Skip images that are already registered. |
| 347 | if (image.HasPose()) { |
| 348 | continue; |
| 349 | } |
| 350 | |
| 351 | // Only consider images with a sufficient number of visible points. |
| 352 | if (obs_manager.NumVisiblePoints3D(image_id) < |
| 353 | static_cast<size_t>(options.abs_pose_min_num_inliers)) { |
| 354 | continue; |
| 355 | } |
| 356 | |
| 357 | // Only try registration for a certain maximum number of times. |
| 358 | const size_t image_num_reg_trials = num_reg_trials[image_id]; |
| 359 | if (image_num_reg_trials >= static_cast<size_t>(options.max_reg_trials)) { |
| 360 | continue; |
| 361 | } |
| 362 | |
| 363 | // If image has been filtered or failed to register, place it in the |
| 364 | // second bucket and prefer images that have not been tried before. |
| 365 | const float rank = rank_image_func(image_id, obs_manager); |
| 366 | const frame_t frame_id = image.FrameId(); |
nothing calls this directly
no test coverage detected