Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vector out of bounds in ViewGraph::KeepLargestConnectedComponents #99

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions glomap/controllers/global_mapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ bool GlobalMapper::Solve(const colmap::Database& database,
RelPoseFilter::FilterInlierRatio(
view_graph, options_.inlier_thresholds.min_inlier_ratio);

view_graph.KeepLargestConnectedComponents(images);
if (view_graph.KeepLargestConnectedComponents(images) == 0) {
LOG(ERROR) << "no connected components are found";
return false;
}

run_timer.PrintSeconds();
}
Expand All @@ -83,7 +86,10 @@ bool GlobalMapper::Solve(const colmap::Database& database,

RelPoseFilter::FilterRotations(
view_graph, images, options_.inlier_thresholds.max_rotation_error);
view_graph.KeepLargestConnectedComponents(images);
if (view_graph.KeepLargestConnectedComponents(images) == 0) {
LOG(ERROR) << "no connected components are found";
return false;
}

// The second run is for final estimation
if (!ra_engine.EstimateRotations(view_graph, images)) {
Expand All @@ -92,6 +98,10 @@ bool GlobalMapper::Solve(const colmap::Database& database,
RelPoseFilter::FilterRotations(
view_graph, images, options_.inlier_thresholds.max_rotation_error);
image_t num_img = view_graph.KeepLargestConnectedComponents(images);
if (num_img == 0) {
LOG(ERROR) << "no connected components are found";
return false;
}
LOG(INFO) << num_img << " / " << images.size()
<< " images are within the connected component." << std::endl;

Expand Down
2 changes: 2 additions & 0 deletions glomap/scene/view_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ int ViewGraph::KeepLargestConnectedComponents(
}
}

if (max_img == 0) return 0;

std::unordered_set<image_t> largest_component = connected_components[max_idx];

// Set all images to not registered
Expand Down