Small updates HashBow

This commit is contained in:
Vladyslav Usenko 2019-06-09 10:29:40 +02:00
parent d67f7c8561
commit 452780ee89
2 changed files with 9 additions and 8 deletions

View File

@ -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<FeatureHash, double> 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;
}

View File

@ -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<FEATURE_HASH_MAX_SIZE>;
using HashBowVector = std::unordered_map<FeatureHash, double>;
using HashBowVector = std::vector<std::pair<FeatureHash, double>>;
/// keypoint positions and descriptors for an image
struct KeypointsData {