30#include "rtabmap/core/rtabmap_core_export.h"
32#include <opencv2/highgui/highgui.hpp>
33#include <opencv2/core/core.hpp>
34#if CV_MAJOR_VERSION < 5
35#include <opencv2/features2d/features2d.hpp>
37#include <opencv2/features.hpp>
41#include "rtabmap/core/Parameters.h"
100 return "FLANN NAIVE";
102 return "FLANN KD-TREE";
106 return "BRUTE FORCE";
107 case kNNBruteForceGPU:
108 return "BRUTE FORCE GPU";
157 const cv::Mat & descriptors,
177 std::vector<int>
findNN(
const std::list<VisualWord *> & vws)
const;
188 std::vector<int>
findNN(
const cv::Mat & descriptors)
const;
238 const std::map<int, VisualWord *> &
getVisualWords()
const {
return _visualWords;}
373 void exportDictionary(
const char * fileNameReferences,
const char * fileNameDescriptors)
const;
381 void clear(
bool printWarningsIfNotEmpty =
true);
433 static cv::Mat
convertBinTo32F(
const cv::Mat & descriptorsIn,
bool byteToFloat =
true);
447 static cv::Mat
convert32FToBin(
const cv::Mat & descriptorsIn,
bool byteToFloat =
true);
473 bool _incrementalDictionary;
478 bool _incrementalFlann;
483 float _rebalancingFactor;
501 std::string _dictionaryPath;
506 std::string _newDictionaryPath;
511 bool _newWordsComparedTogether;
516 bool _serializeWithChecksum;
551 std::map<int ,int> _mapIndexId;
556 std::map<int ,int> _mapIdIndex;
562 std::map<int, VisualWord*> _unusedWords;
566 std::set<int> _notIndexedWords;
571 std::set<int> _removedIndexedWords;
Manages a dictionary of visual words for visual place recognition and loop closure detection.
int getNextId()
Get the next available visual word ID.
bool deserializeIndex(const unsigned char *data, size_t size)
Deserialize the search index from raw bytes.
unsigned int getUnusedWordsSize() const
Get the count of unused visual words.
void exportDictionary(const char *fileNameReferences, const char *fileNameDescriptors) const
Export the dictionary to files.
std::vector< unsigned char > serializeIndex() const
Serialize the search index to a byte vector.
unsigned int getNotIndexedWordsCount() const
Get the count of words not yet indexed in the search tree.
virtual std::list< int > addNewWords(const cv::Mat &descriptors, int signatureId)
Add new visual words from descriptors.
static const int ID_START
Starting ID for visual words (typically 1)
void deleteUnusedWords()
Delete all unused visual words.
bool deserializeIndex(const std::vector< unsigned char > &data)
Deserialize the search index from a byte vector.
float getNndrRatio() const
Get the Nearest Neighbor Distance Ratio (NNDR) threshold.
int _totalActiveReferences
Total count of active word-to-signature references.
void clear(bool printWarningsIfNotEmpty=true)
Clear all visual words and reset the dictionary.
const VisualWord * getWord(int id) const
Get a visual word by ID.
void setFixedDictionary(const std::string &dictionaryPath)
Set the dictionary to fixed mode and load from file.
unsigned int getIndexMemoryUsed() const
Get the memory used by the search index.
std::vector< int > getUnusedWordIds() const
Get IDs of all unused visual words.
int getLastIndexedWordId() const
Get the ID of the last indexed word.
unsigned int getIndexedWordsCount() const
Get the count of words currently indexed in the search tree.
const std::map< int, VisualWord * > & getVisualWords() const
Get all visual words.
bool isIncremental() const
Check if the dictionary is in incremental mode.
static std::string nnStrategyName(NNStrategy strategy)
Get the name of a nearest neighbor strategy.
static cv::Mat convertBinTo32F(const cv::Mat &descriptorsIn, bool byteToFloat=true)
Convert binary descriptors to 32-bit float format.
void removeWords(const std::vector< VisualWord * > &words)
Remove words from the dictionary.
static const int ID_INVALID
Invalid visual word ID (typically 0)
virtual void update()
Update the search index with newly added words.
virtual void parseParameters(const ParametersMap ¶meters)
Parse and apply parameters from a parameters map.
NNStrategy
Nearest neighbor search strategies for descriptor matching.
@ kNNBruteForce
Brute force CPU search.
@ kNNBruteForceGPU
Brute force GPU-accelerated search (requires CUDA)
@ kNNFlannLSH
FLANN Locality-Sensitive Hashing (ideal for binary descriptors)
@ kNNFlannKdTree
FLANN kd-tree index (fast for high-dimensional descriptors)
@ kNNFlannNaive
FLANN naive search (exhaustive)
int getTotalActiveReferences() const
Get the total number of active word-to-signature references.
bool isIncrementalFlann() const
Check if FLANN index is updated incrementally.
bool isModified() const
Check if the dictionary has been modified since last save.
std::vector< int > findNN(const cv::Mat &descriptors) const
Find nearest neighbor visual word IDs for descriptors.
void setIncrementalDictionary()
Set the dictionary to incremental mode.
NNStrategy getNNStrategy() const
Get the current nearest neighbor search strategy.
std::vector< VisualWord * > getUnusedWords() const
Get all unused visual words.
VisualWord * getUnusedWord(int id) const
Get an unused visual word by ID.
std::vector< int > findNN(const std::list< VisualWord * > &vws) const
Find nearest neighbor visual word IDs for a list of visual words.
void removeAllWordRef(int wordId, int signatureId)
Remove all references from a visual word to a signature.
unsigned long getMemoryUsed() const
Get the total memory used by the dictionary.
static cv::Mat convert32FToBin(const cv::Mat &descriptorsIn, bool byteToFloat=true)
Convert 32-bit float descriptors to binary format.
virtual void addWord(VisualWord *vw)
Add an existing visual word to the dictionary.
VWDictionary(const ParametersMap ¶meters=ParametersMap())
Constructor.
std::map< int, VisualWord * > _visualWords
Map of visual word ID to VisualWord pointer.
bool addWordRef(int wordId, int signatureId)
Add a reference from a visual word to a signature.
void setLastWordId(int id)
Set the last word ID (used when loading from database)
bool setNNStrategy(NNStrategy strategy)
Set the nearest neighbor search strategy.
virtual ~VWDictionary()
Destructor.
Represents a visual word (feature descriptor) used in the bag-of-words (BoW) model.
std::map< std::string, std::string > ParametersMap
Parameter keys mapped to their values, as used by every configurable class (see Parameters).