From c50a1c2b7ece0b67dfc48e02271c1a7d31de240b Mon Sep 17 00:00:00 2001 From: ymd-stella <7959916+ymd-stella@users.noreply.github.com> Date: Sat, 14 Oct 2023 19:56:53 +0900 Subject: [PATCH] Add option num_common_words_thr_ratio (#536) --- src/stella_vslam/data/bow_database.cc | 3 ++- src/stella_vslam/data/bow_database.h | 1 + src/stella_vslam/module/loop_detector.cc | 5 +++-- src/stella_vslam/module/loop_detector.h | 2 ++ src/stella_vslam/module/relocalizer.cc | 11 +++++++---- src/stella_vslam/module/relocalizer.h | 5 ++++- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/stella_vslam/data/bow_database.cc b/src/stella_vslam/data/bow_database.cc index e9771f1f4..6bb5f191e 100644 --- a/src/stella_vslam/data/bow_database.cc +++ b/src/stella_vslam/data/bow_database.cc @@ -56,6 +56,7 @@ void bow_database::clear() { } std::vector> bow_database::acquire_keyframes(const bow_vector& bow_vec, const float min_score, + const float num_common_words_thr_ratio, const std::set>& keyfrms_to_reject) { // Step 1. // Count up the number of nodes, words which are shared with query_keyframe, for all the keyframes in DoW database @@ -74,7 +75,7 @@ std::vector> bow_database::acquire_keyframes(const bow max_num_common_words = keyfrm_num_common_words_pair.second; } } - const auto min_num_common_words_thr = static_cast(0.8f * max_num_common_words); + const auto min_num_common_words_thr = static_cast(num_common_words_thr_ratio * max_num_common_words); // Step 2. // Collect keyframe candidates which have more shared words than min_num_common_words_thr diff --git a/src/stella_vslam/data/bow_database.h b/src/stella_vslam/data/bow_database.h index 134ef70eb..62dff6684 100644 --- a/src/stella_vslam/data/bow_database.h +++ b/src/stella_vslam/data/bow_database.h @@ -51,6 +51,7 @@ class bow_database { * Acquire keyframes over score */ std::vector> acquire_keyframes(const bow_vector& bow_vec, const float min_score = 0.0f, + const float num_common_words_thr_ratio = 0.8f, const std::set>& keyfrms_to_reject = {}); protected: diff --git a/src/stella_vslam/module/loop_detector.cc b/src/stella_vslam/module/loop_detector.cc index 12eae977d..ab620ceda 100644 --- a/src/stella_vslam/module/loop_detector.cc +++ b/src/stella_vslam/module/loop_detector.cc @@ -28,7 +28,8 @@ loop_detector::loop_detector(data::bow_database* bow_db, data::bow_vocabulary* b num_matches_thr_brute_force_(yaml_node["num_matches_thr_robust_matcher"].as(0)), num_optimized_inliers_thr_(yaml_node["num_optimized_inliers_thr"].as(20)), top_n_covisibilities_to_search_(yaml_node["top_n_covisibilities_to_search"].as(0)), - use_fixed_seed_(yaml_node["use_fixed_seed"].as(false)) { + use_fixed_seed_(yaml_node["use_fixed_seed"].as(false)), + num_common_words_thr_ratio_(yaml_node["num_common_words_thr_ratio"].as(0.8f)) { spdlog::debug("CONSTRUCT: loop_detector"); } @@ -116,7 +117,7 @@ bool loop_detector::detect_loop_candidates_impl() { } } - const auto init_loop_candidates = bow_db_->acquire_keyframes(cur_keyfrm_->bow_vec_, min_score, keyfrms_to_reject); + const auto init_loop_candidates = bow_db_->acquire_keyframes(cur_keyfrm_->bow_vec_, min_score, num_common_words_thr_ratio_, keyfrms_to_reject); // 1-3. if no candidates are found, cannot perform the loop correction diff --git a/src/stella_vslam/module/loop_detector.h b/src/stella_vslam/module/loop_detector.h index 1af64a09c..ca418948d 100644 --- a/src/stella_vslam/module/loop_detector.h +++ b/src/stella_vslam/module/loop_detector.h @@ -192,6 +192,8 @@ class loop_detector { //! Use fixed random seed for RANSAC if true const bool use_fixed_seed_; + + const float num_common_words_thr_ratio_ = 0.8f; }; } // namespace module diff --git a/src/stella_vslam/module/relocalizer.cc b/src/stella_vslam/module/relocalizer.cc index 35db41265..850878d0e 100644 --- a/src/stella_vslam/module/relocalizer.cc +++ b/src/stella_vslam/module/relocalizer.cc @@ -18,13 +18,15 @@ relocalizer::relocalizer(const std::shared_ptr& pose_o const unsigned int min_num_bow_matches, const unsigned int min_num_valid_obs, const bool use_fixed_seed, const bool search_neighbor, - const unsigned int top_n_covisibilities_to_search) + const unsigned int top_n_covisibilities_to_search, + const float num_common_words_thr_ratio) : min_num_bow_matches_(min_num_bow_matches), min_num_valid_obs_(min_num_valid_obs), bow_matcher_(bow_match_lowe_ratio, false), proj_matcher_(proj_match_lowe_ratio, false), robust_matcher_(robust_match_lowe_ratio, false), pose_optimizer_(pose_optimizer), use_fixed_seed_(use_fixed_seed), search_neighbor_(search_neighbor), - top_n_covisibilities_to_search_(top_n_covisibilities_to_search) { + top_n_covisibilities_to_search_(top_n_covisibilities_to_search), + num_common_words_thr_ratio_(num_common_words_thr_ratio) { spdlog::debug("CONSTRUCT: module::relocalizer"); } @@ -37,7 +39,8 @@ relocalizer::relocalizer(const std::shared_ptr& pose_o yaml_node["min_num_valid_obs"].as(50), yaml_node["use_fixed_seed"].as(false), yaml_node["search_neighbor"].as(true), - yaml_node["top_n_covisibilities_to_search"].as(10)) { + yaml_node["top_n_covisibilities_to_search"].as(10), + yaml_node["num_common_words_thr_ratio"].as(0.8f)) { } relocalizer::~relocalizer() { @@ -46,7 +49,7 @@ relocalizer::~relocalizer() { bool relocalizer::relocalize(data::bow_database* bow_db, data::frame& curr_frm) { // Acquire relocalization candidates - const auto reloc_candidates = bow_db->acquire_keyframes(curr_frm.bow_vec_); + const auto reloc_candidates = bow_db->acquire_keyframes(curr_frm.bow_vec_, 0.0f, num_common_words_thr_ratio_); if (reloc_candidates.empty()) { return false; } diff --git a/src/stella_vslam/module/relocalizer.h b/src/stella_vslam/module/relocalizer.h index 508e61c41..47b48776c 100644 --- a/src/stella_vslam/module/relocalizer.h +++ b/src/stella_vslam/module/relocalizer.h @@ -27,7 +27,8 @@ class relocalizer { const unsigned int min_num_bow_matches = 20, const unsigned int min_num_valid_obs = 50, const bool use_fixed_seed = false, const bool search_neighbor = true, - const unsigned int top_n_covisibilities_to_search = 10); + const unsigned int top_n_covisibilities_to_search = 10, + const float num_common_words_thr_ratio = 0.8f); explicit relocalizer(const std::shared_ptr& pose_optimizer, const YAML::Node& yaml_node); @@ -90,6 +91,8 @@ class relocalizer { const bool search_neighbor_ = true; //! number of neighbor keyframes const unsigned int top_n_covisibilities_to_search_ = 10; + + const float num_common_words_thr_ratio_ = 0.8f; }; } // namespace module