Skip to content

Commit

Permalink
Add option num_common_words_thr_ratio (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymd-stella committed Oct 14, 2023
1 parent f6c7f83 commit c50a1c2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/stella_vslam/data/bow_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void bow_database::clear() {
}

std::vector<std::shared_ptr<keyframe>> bow_database::acquire_keyframes(const bow_vector& bow_vec, const float min_score,
const float num_common_words_thr_ratio,
const std::set<std::shared_ptr<keyframe>>& 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
Expand All @@ -74,7 +75,7 @@ std::vector<std::shared_ptr<keyframe>> 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<unsigned int>(0.8f * max_num_common_words);
const auto min_num_common_words_thr = static_cast<unsigned int>(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
Expand Down
1 change: 1 addition & 0 deletions src/stella_vslam/data/bow_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class bow_database {
* Acquire keyframes over score
*/
std::vector<std::shared_ptr<keyframe>> 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<std::shared_ptr<keyframe>>& keyfrms_to_reject = {});

protected:
Expand Down
5 changes: 3 additions & 2 deletions src/stella_vslam/module/loop_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(0)),
num_optimized_inliers_thr_(yaml_node["num_optimized_inliers_thr"].as<unsigned int>(20)),
top_n_covisibilities_to_search_(yaml_node["top_n_covisibilities_to_search"].as<unsigned int>(0)),
use_fixed_seed_(yaml_node["use_fixed_seed"].as<bool>(false)) {
use_fixed_seed_(yaml_node["use_fixed_seed"].as<bool>(false)),
num_common_words_thr_ratio_(yaml_node["num_common_words_thr_ratio"].as<float>(0.8f)) {
spdlog::debug("CONSTRUCT: loop_detector");
}

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/stella_vslam/module/loop_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/stella_vslam/module/relocalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ relocalizer::relocalizer(const std::shared_ptr<optimize::pose_optimizer>& 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");
}

Expand All @@ -37,7 +39,8 @@ relocalizer::relocalizer(const std::shared_ptr<optimize::pose_optimizer>& pose_o
yaml_node["min_num_valid_obs"].as<unsigned int>(50),
yaml_node["use_fixed_seed"].as<bool>(false),
yaml_node["search_neighbor"].as<bool>(true),
yaml_node["top_n_covisibilities_to_search"].as<unsigned int>(10)) {
yaml_node["top_n_covisibilities_to_search"].as<unsigned int>(10),
yaml_node["num_common_words_thr_ratio"].as<float>(0.8f)) {
}

relocalizer::~relocalizer() {
Expand All @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/stella_vslam/module/relocalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<optimize::pose_optimizer>& pose_optimizer, const YAML::Node& yaml_node);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c50a1c2

Please sign in to comment.