Small updates HashBow
This commit is contained in:
		
							parent
							
								
									d67f7c8561
								
							
						
					
					
						commit
						452780ee89
					
				| @ -35,23 +35,24 @@ class HashBow { | |||||||
|     size_t descriptors_size = descriptors.size(); |     size_t descriptors_size = descriptors.size(); | ||||||
|     hashes.resize(descriptors_size); |     hashes.resize(descriptors_size); | ||||||
| 
 | 
 | ||||||
|     bow_vector.clear(); |     std::unordered_map<FeatureHash, double> bow_map; | ||||||
|     bow_vector.reserve(descriptors_size); |     bow_map.clear(); | ||||||
|  |     bow_map.reserve(descriptors_size); | ||||||
| 
 | 
 | ||||||
|     for (size_t i = 0; i < descriptors_size; i++) { |     for (size_t i = 0; i < descriptors_size; i++) { | ||||||
|       hashes[i] = compute_hash(descriptors[i]); |       hashes[i] = compute_hash(descriptors[i]); | ||||||
| 
 |       bow_map[hashes[i]] += 1.0; | ||||||
|       FeatureHash bow_word = hashes[i]; |  | ||||||
|       bow_vector[bow_word] += 1.0; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     bow_vector.clear(); | ||||||
|  | 
 | ||||||
|     double sum_squared = 0; |     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; |       sum_squared += kv.second * kv.second; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     double norm = std::sqrt(sum_squared); |     double norm = std::sqrt(sum_squared); | ||||||
| 
 |  | ||||||
|     for (auto& kv : bow_vector) { |     for (auto& kv : bow_vector) { | ||||||
|       kv.second /= norm; |       kv.second /= norm; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -66,7 +66,7 @@ inline std::ostream& operator<<(std::ostream& os, const TimeCamId& tcid) { | |||||||
| 
 | 
 | ||||||
| constexpr static const size_t FEATURE_HASH_MAX_SIZE = 32; | constexpr static const size_t FEATURE_HASH_MAX_SIZE = 32; | ||||||
| using FeatureHash = std::bitset<FEATURE_HASH_MAX_SIZE>; | 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
 | /// keypoint positions and descriptors for an image
 | ||||||
| struct KeypointsData { | struct KeypointsData { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user