From 452780ee89a48109e3d27b8c230f09dfa235fb19 Mon Sep 17 00:00:00 2001 From: Vladyslav Usenko Date: Sun, 9 Jun 2019 10:29:40 +0200 Subject: [PATCH] Small updates HashBow --- include/basalt/hash_bow/hash_bow.h | 15 ++++++++------- include/basalt/utils/common_types.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/basalt/hash_bow/hash_bow.h b/include/basalt/hash_bow/hash_bow.h index 0c658d2..a2936f0 100644 --- a/include/basalt/hash_bow/hash_bow.h +++ b/include/basalt/hash_bow/hash_bow.h @@ -35,23 +35,24 @@ class HashBow { size_t descriptors_size = descriptors.size(); hashes.resize(descriptors_size); - bow_vector.clear(); - bow_vector.reserve(descriptors_size); + std::unordered_map bow_map; + bow_map.clear(); + bow_map.reserve(descriptors_size); for (size_t i = 0; i < descriptors_size; i++) { hashes[i] = compute_hash(descriptors[i]); - - FeatureHash bow_word = hashes[i]; - bow_vector[bow_word] += 1.0; + bow_map[hashes[i]] += 1.0; } + bow_vector.clear(); + double sum_squared = 0; - for (const auto& kv : bow_vector) { + for (const auto& kv : bow_map) { + bow_vector.emplace_back(kv); sum_squared += kv.second * kv.second; } double norm = std::sqrt(sum_squared); - for (auto& kv : bow_vector) { kv.second /= norm; } diff --git a/include/basalt/utils/common_types.h b/include/basalt/utils/common_types.h index e3d9a2e..dc983dc 100644 --- a/include/basalt/utils/common_types.h +++ b/include/basalt/utils/common_types.h @@ -66,7 +66,7 @@ inline std::ostream& operator<<(std::ostream& os, const TimeCamId& tcid) { constexpr static const size_t FEATURE_HASH_MAX_SIZE = 32; using FeatureHash = std::bitset; -using HashBowVector = std::unordered_map; +using HashBowVector = std::vector>; /// keypoint positions and descriptors for an image struct KeypointsData {