|
RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
|
Manages a dictionary of visual words for visual place recognition and loop closure detection. More...
#include <VWDictionary.h>
Public Types | |
| enum | NNStrategy { kNNFlannNaive , kNNFlannKdTree , kNNFlannLSH , kNNBruteForce , kNNBruteForceGPU , kNNUndef } |
| Nearest neighbor search strategies for descriptor matching. More... | |
Public Member Functions | |
| VWDictionary (const ParametersMap ¶meters=ParametersMap()) | |
| Constructor. | |
| virtual | ~VWDictionary () |
| Destructor. | |
| virtual void | parseParameters (const ParametersMap ¶meters) |
| Parse and apply parameters from a parameters map. | |
| virtual void | update () |
| Update the search index with newly added words. | |
| virtual std::list< int > | addNewWords (const cv::Mat &descriptors, int signatureId) |
| Add new visual words from descriptors. | |
| virtual void | addWord (VisualWord *vw) |
| Add an existing visual word to the dictionary. | |
| std::vector< int > | findNN (const std::list< VisualWord * > &vws) const |
| Find nearest neighbor visual word IDs for a list of visual words. | |
| std::vector< int > | findNN (const cv::Mat &descriptors) const |
| Find nearest neighbor visual word IDs for descriptors. | |
| bool | addWordRef (int wordId, int signatureId) |
| Add a reference from a visual word to a signature. | |
| void | removeAllWordRef (int wordId, int signatureId) |
| Remove all references from a visual word to a signature. | |
| const VisualWord * | getWord (int id) const |
| Get a visual word by ID. | |
| VisualWord * | getUnusedWord (int id) const |
| Get an unused visual word by ID. | |
| void | setLastWordId (int id) |
| Set the last word ID (used when loading from database) | |
| const std::map< int, VisualWord * > & | getVisualWords () const |
| Get all visual words. | |
| float | getNndrRatio () const |
| Get the Nearest Neighbor Distance Ratio (NNDR) threshold. | |
| unsigned int | getNotIndexedWordsCount () const |
| Get the count of words not yet indexed in the search tree. | |
| int | getLastIndexedWordId () const |
| Get the ID of the last indexed word. | |
| int | getTotalActiveReferences () const |
| Get the total number of active word-to-signature references. | |
| unsigned int | getIndexedWordsCount () const |
| Get the count of words currently indexed in the search tree. | |
| unsigned int | getIndexMemoryUsed () const |
| Get the memory used by the search index. | |
| unsigned long | getMemoryUsed () const |
| Get the total memory used by the dictionary. | |
| bool | setNNStrategy (NNStrategy strategy) |
| Set the nearest neighbor search strategy. | |
| NNStrategy | getNNStrategy () const |
| Get the current nearest neighbor search strategy. | |
| bool | isIncremental () const |
| Check if the dictionary is in incremental mode. | |
| bool | isIncrementalFlann () const |
| Check if FLANN index is updated incrementally. | |
| void | setIncrementalDictionary () |
| Set the dictionary to incremental mode. | |
| void | setFixedDictionary (const std::string &dictionaryPath) |
| Set the dictionary to fixed mode and load from file. | |
| bool | isModified () const |
| Check if the dictionary has been modified since last save. | |
| void | rebuildIndex () |
| std::vector< unsigned char > | serializeIndex () const |
| Serialize the search index to a byte vector. | |
| bool | deserializeIndex (const std::vector< unsigned char > &data) |
| Deserialize the search index from a byte vector. | |
| bool | deserializeIndex (const unsigned char *data, size_t size) |
| Deserialize the search index from raw bytes. | |
| void | exportDictionary (const char *fileNameReferences, const char *fileNameDescriptors) const |
| Export the dictionary to files. | |
| void | clear (bool printWarningsIfNotEmpty=true) |
| Clear all visual words and reset the dictionary. | |
| std::vector< VisualWord * > | getUnusedWords () const |
| Get all unused visual words. | |
| std::vector< int > | getUnusedWordIds () const |
| Get IDs of all unused visual words. | |
| unsigned int | getUnusedWordsSize () const |
| Get the count of unused visual words. | |
| void | removeWords (const std::vector< VisualWord * > &words) |
| Remove words from the dictionary. | |
| void | deleteUnusedWords () |
| Delete all unused visual words. | |
Static Public Member Functions | |
| 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. | |
| static cv::Mat | convert32FToBin (const cv::Mat &descriptorsIn, bool byteToFloat=true) |
| Convert 32-bit float descriptors to binary format. | |
Static Public Attributes | |
| static const int | ID_START |
| Starting ID for visual words (typically 1) | |
| static const int | ID_INVALID |
| Invalid visual word ID (typically 0) | |
Protected Member Functions | |
| int | getNextId () |
| Get the next available visual word ID. | |
Protected Attributes | |
| std::map< int, VisualWord * > | _visualWords |
| Map of visual word ID to VisualWord pointer. | |
| int | _totalActiveReferences |
| Total count of active word-to-signature references. | |
Manages a dictionary of visual words for visual place recognition and loop closure detection.
The VWDictionary class maintains a collection of visual words (feature descriptors) and provides efficient nearest neighbor search capabilities. It supports both incremental and fixed dictionary modes:
The class uses various nearest neighbor search strategies (FLANN, brute force, GPU-accelerated) to match descriptors efficiently. It tracks word references to signatures (images) and manages unused words for memory optimization.
Definition at line 65 of file VWDictionary.h.
Nearest neighbor search strategies for descriptor matching.
Definition at line 72 of file VWDictionary.h.
| rtabmap::VWDictionary::VWDictionary | ( | const ParametersMap & | parameters = ParametersMap() | ) |
Constructor.
| parameters | Optional parameters map to configure the dictionary |
|
virtual |
Destructor.
Clears all visual words and releases resources.
|
inlinestatic |
Get the name of a nearest neighbor strategy.
| strategy | The strategy enum value |
Definition at line 96 of file VWDictionary.h.
|
virtual |
Parse and apply parameters from a parameters map.
| parameters | Parameters map containing configuration values |
|
virtual |
Update the search index with newly added words.
This method rebuilds the nearest neighbor search index (FLANN, etc.) to include any words that were added but not yet indexed.
|
virtual |
Add new visual words from descriptors.
| descriptors | Matrix of descriptors (one row per descriptor) |
| signatureId | ID of the signature (image) these descriptors belong to |
For each descriptor, either matches it to an existing visual word (using nearest neighbor search with NNDR ratio) or creates a new visual word.
|
virtual |
Add an existing visual word to the dictionary.
| vw | Pointer to the visual word to add (ownership is transferred) |
| std::vector< int > rtabmap::VWDictionary::findNN | ( | const std::list< VisualWord * > & | vws | ) | const |
Find nearest neighbor visual word IDs for a list of visual words.
| vws | List of visual words to match |
| std::vector< int > rtabmap::VWDictionary::findNN | ( | const cv::Mat & | descriptors | ) | const |
Find nearest neighbor visual word IDs for descriptors.
| descriptors | Matrix of descriptors (one row per descriptor) |
| bool rtabmap::VWDictionary::addWordRef | ( | int | wordId, |
| int | signatureId | ||
| ) |
Add a reference from a visual word to a signature.
| wordId | ID of the visual word |
| signatureId | ID of the signature (image) |
Tracks which signatures use which visual words. If the word was unused, it is removed from the unused words list.
| void rtabmap::VWDictionary::removeAllWordRef | ( | int | wordId, |
| int | signatureId | ||
| ) |
Remove all references from a visual word to a signature.
| wordId | ID of the visual word |
| signatureId | ID of the signature (image) |
If the word has no more references after this operation, it is added to the unused words list.
| const VisualWord * rtabmap::VWDictionary::getWord | ( | int | id | ) | const |
Get a visual word by ID.
| id | Visual word ID |
| VisualWord * rtabmap::VWDictionary::getUnusedWord | ( | int | id | ) | const |
Get an unused visual word by ID.
| id | Visual word ID |
|
inline |
Set the last word ID (used when loading from database)
| id | Last word ID |
Definition at line 232 of file VWDictionary.h.
|
inline |
Get all visual words.
Definition at line 238 of file VWDictionary.h.
|
inline |
Get the Nearest Neighbor Distance Ratio (NNDR) threshold.
The NNDR ratio is used to determine if a descriptor matches an existing visual word. If the ratio of distances to the first and second nearest neighbors is below this threshold, a match is accepted.
Definition at line 251 of file VWDictionary.h.
|
inline |
Get the count of words not yet indexed in the search tree.
Definition at line 257 of file VWDictionary.h.
| int rtabmap::VWDictionary::getLastIndexedWordId | ( | ) | const |
Get the ID of the last indexed word.
|
inline |
Get the total number of active word-to-signature references.
Definition at line 269 of file VWDictionary.h.
| unsigned int rtabmap::VWDictionary::getIndexedWordsCount | ( | ) | const |
Get the count of words currently indexed in the search tree.
| unsigned int rtabmap::VWDictionary::getIndexMemoryUsed | ( | ) | const |
Get the memory used by the search index.
| unsigned long rtabmap::VWDictionary::getMemoryUsed | ( | ) | const |
Get the total memory used by the dictionary.
| bool rtabmap::VWDictionary::setNNStrategy | ( | NNStrategy | strategy | ) |
Set the nearest neighbor search strategy.
| strategy | The strategy to use |
Changing the strategy will rebuild the search index if words are already indexed.
|
inline |
Get the current nearest neighbor search strategy.
Definition at line 302 of file VWDictionary.h.
|
inline |
Check if the dictionary is in incremental mode.
Definition at line 308 of file VWDictionary.h.
|
inline |
Check if FLANN index is updated incrementally.
Definition at line 314 of file VWDictionary.h.
| void rtabmap::VWDictionary::setIncrementalDictionary | ( | ) |
Set the dictionary to incremental mode.
In incremental mode, new visual words can be added dynamically. This cannot be called if a fixed dictionary is already loaded.
| void rtabmap::VWDictionary::setFixedDictionary | ( | const std::string & | dictionaryPath | ) |
Set the dictionary to fixed mode and load from file.
| dictionaryPath | Path to the dictionary file (.txt or .db format) |
Loads a pre-computed dictionary from a file. The dictionary file format in txt format should be: one line per visual word, with word ID followed by descriptor values. This cannot be called if words are already in the dictionary.
| bool rtabmap::VWDictionary::isModified | ( | ) | const |
Check if the dictionary has been modified since last save.
| std::vector< unsigned char > rtabmap::VWDictionary::serializeIndex | ( | ) | const |
Serialize the search index to a byte vector.
| bool rtabmap::VWDictionary::deserializeIndex | ( | const std::vector< unsigned char > & | data | ) |
Deserialize the search index from a byte vector.
| data | Serialized index data |
| bool rtabmap::VWDictionary::deserializeIndex | ( | const unsigned char * | data, |
| size_t | size | ||
| ) |
Deserialize the search index from raw bytes.
| data | Pointer to serialized index data |
| size | Size of the data in bytes |
| void rtabmap::VWDictionary::exportDictionary | ( | const char * | fileNameReferences, |
| const char * | fileNameDescriptors | ||
| ) | const |
Export the dictionary to files.
| fileNameReferences | Path to file for word-to-signature references |
| fileNameDescriptors | Path to file for visual word descriptors |
Exports the dictionary in a format that can be loaded later.
| void rtabmap::VWDictionary::clear | ( | bool | printWarningsIfNotEmpty = true | ) |
Clear all visual words and reset the dictionary.
| printWarningsIfNotEmpty | If true, print warnings if dictionary is not empty |
Deletes all visual words and releases all resources.
| std::vector< VisualWord * > rtabmap::VWDictionary::getUnusedWords | ( | ) | const |
Get all unused visual words.
Unused words are visual words that have no references to any signatures.
| std::vector< int > rtabmap::VWDictionary::getUnusedWordIds | ( | ) | const |
Get IDs of all unused visual words.
|
inline |
Get the count of unused visual words.
Definition at line 404 of file VWDictionary.h.
| void rtabmap::VWDictionary::removeWords | ( | const std::vector< VisualWord * > & | words | ) |
Remove words from the dictionary.
| words | Vector of visual word pointers to remove |
| void rtabmap::VWDictionary::deleteUnusedWords | ( | ) |
Delete all unused visual words.
Removes and deletes visual words that have no references to any signatures.
|
static |
Convert binary descriptors to 32-bit float format.
| descriptorsIn | Input descriptors (CV_8UC1 for binary, or CV_32FC1 for float) |
| byteToFloat | Conversion mode:
|
|
static |
Convert 32-bit float descriptors to binary format.
| descriptorsIn | Input descriptors (CV_32FC1) |
| byteToFloat | Conversion mode:
|
|
protected |
Get the next available visual word ID.
|
static |
Starting ID for visual words (typically 1)
Definition at line 84 of file VWDictionary.h.
|
static |
Invalid visual word ID (typically 0)
Definition at line 89 of file VWDictionary.h.
|
protected |
Map of visual word ID to VisualWord pointer.
Definition at line 461 of file VWDictionary.h.
|
protected |
Total count of active word-to-signature references.
Definition at line 467 of file VWDictionary.h.