From adfee7e2ff8a4ad8d6a359533468d27ce98da48c Mon Sep 17 00:00:00 2001 From: Linfei Pan Date: Tue, 17 Dec 2024 16:28:05 +0100 Subject: [PATCH 1/2] add fix for 0 focal length --- glomap/estimators/view_graph_calibration.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/glomap/estimators/view_graph_calibration.cc b/glomap/estimators/view_graph_calibration.cc index 30c7d343..2af15017 100644 --- a/glomap/estimators/view_graph_calibration.cc +++ b/glomap/estimators/view_graph_calibration.cc @@ -55,6 +55,11 @@ void ViewGraphCalibrator::Reset( focals_.reserve(cameras.size()); for (const auto& [camera_id, camera] : cameras) { focals_[camera_id] = camera.Focal(); + // Avoid zero focal length + if (focals_[camera_id] < 1e-3) { + focals_[camera_id] = + std::max(std::max(camera.width, camera.height) * 1.2, 1e-3); + } } // Set up the problem @@ -179,7 +184,7 @@ size_t ViewGraphCalibrator::FilterImagePairs(ViewGraph& view_graph) const { } LOG(INFO) << "invalid / total number of two view geometry: " - << invalid_counter << " / " << counter; + << invalid_counter << " / " << (counter / 2); return invalid_counter; } From e441804b7af67d50d0a52bea76fe265102eb7fe0 Mon Sep 17 00:00:00 2001 From: Linfei Pan Date: Tue, 17 Dec 2024 16:28:39 +0100 Subject: [PATCH 2/2] load only valid image pairs --- glomap/io/colmap_converter.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/glomap/io/colmap_converter.cc b/glomap/io/colmap_converter.cc index a52455cd..ad67703f 100644 --- a/glomap/io/colmap_converter.cc +++ b/glomap/io/colmap_converter.cc @@ -220,27 +220,31 @@ void ConvertDatabaseToGlomap(const colmap::Database& database, cameras[camera_id] = camera; } - // Add the matches - std::vector> - all_matches = database.ReadAllMatches(); + // Add the valid matches + std::vector> two_view_geometries_inliers = + database.ReadTwoViewGeometryNumInliers(); // Go through all matches and store the matche with enough observations in the // view_graph size_t invalid_count = 0; std::unordered_map& image_pairs = view_graph.image_pairs; - for (size_t match_idx = 0; match_idx < all_matches.size(); match_idx++) { - if ((match_idx + 1) % 1000 == 0 || match_idx == all_matches.size() - 1) + for (size_t match_idx = 0; match_idx < two_view_geometries_inliers.size(); + match_idx++) { + if ((match_idx + 1) % 1000 == 0 || + match_idx == two_view_geometries_inliers.size() - 1) std::cout << "\r Loading Image Pair " << match_idx + 1 << " / " - << all_matches.size() << std::flush; + << two_view_geometries_inliers.size() << std::flush; // Read the image pair from COLMAP database - colmap::image_pair_t pair_id = all_matches[match_idx].first; + colmap::image_pair_t pair_id = two_view_geometries_inliers[match_idx].first; std::pair image_pair_colmap = database.PairIdToImagePair(pair_id); colmap::image_t image_id1 = image_pair_colmap.first; colmap::image_t image_id2 = image_pair_colmap.second; - colmap::FeatureMatches& feature_matches = all_matches[match_idx].second; + // colmap::FeatureMatches& feature_matches = all_matches[match_idx].second; + colmap::FeatureMatches feature_matches = + database.ReadMatches(image_id1, image_id2); // Initialize the image pair auto ite = image_pairs.insert(