Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #pragma once
00029
00030 #include "rtabmap/core/RtabmapExp.h"
00031
00032 #include <opencv2/highgui/highgui.hpp>
00033 #include <opencv2/core/core.hpp>
00034 #include <opencv2/features2d/features2d.hpp>
00035 #include <list>
00036 #include <set>
00037 #include "rtabmap/core/Parameters.h"
00038
00039 namespace rtabmap
00040 {
00041
00042 class DBDriver;
00043 class VisualWord;
00044
00045 class RTABMAP_EXP VWDictionary
00046 {
00047 public:
00048 enum NNStrategy{kNNFlannNaive, kNNFlannKdTree, kNNFlannLSH, kNNBruteForce, kNNBruteForceGPU, kNNUndef};
00049 static const int ID_START;
00050 static const int ID_INVALID;
00051
00052 public:
00053 VWDictionary(const ParametersMap & parameters = ParametersMap());
00054 virtual ~VWDictionary();
00055
00056 virtual void parseParameters(const ParametersMap & parameters);
00057
00058 virtual void update();
00059
00060 virtual std::list<int> addNewWords(
00061 const cv::Mat & descriptors,
00062 int signatureId);
00063 virtual void addWord(VisualWord * vw);
00064
00065 virtual std::vector<int> findNN(const std::list<VisualWord *> & vws) const;
00066
00067 void addWordRef(int wordId, int signatureId);
00068 void removeAllWordRef(int wordId, int signatureId);
00069 const VisualWord * getWord(int id) const;
00070 VisualWord * getUnusedWord(int id) const;
00071 void setLastWordId(int id) {_lastWordId = id;}
00072 const std::map<int, VisualWord *> & getVisualWords() const {return _visualWords;}
00073 float getNndrRatio() const {return _nndrRatio;}
00074 unsigned int getNotIndexedWordsCount() const {return (int)_notIndexedWords.size();}
00075 int getLastIndexedWordId() const;
00076 int getTotalActiveReferences() const {return _totalActiveReferences;}
00077 void setNNStrategy(NNStrategy strategy);
00078 bool isIncremental() const {return _incrementalDictionary;}
00079 void setIncrementalDictionary();
00080 void setFixedDictionary(const std::string & dictionaryPath);
00081
00082 void exportDictionary(const char * fileNameReferences, const char * fileNameDescriptors) const;
00083
00084 void clear();
00085 std::vector<VisualWord *> getUnusedWords() const;
00086 std::vector<int> getUnusedWordIds() const;
00087 unsigned int getUnusedWordsSize() const {return (int)_unusedWords.size();}
00088 void removeWords(const std::vector<VisualWord*> & words);
00089 void deleteUnusedWords();
00090
00091 protected:
00092 int getNextId();
00093
00094 protected:
00095 std::map<int, VisualWord *> _visualWords;
00096 int _totalActiveReferences;
00097
00098 private:
00099 bool _incrementalDictionary;
00100 float _nndrRatio;
00101 std::string _dictionaryPath;
00102 bool _newWordsComparedTogether;
00103 int _lastWordId;
00104 cv::flann::Index * _flannIndex;
00105 cv::Mat _dataTree;
00106 NNStrategy _strategy;
00107 std::map<int ,int> _mapIndexId;
00108 std::map<int, VisualWord*> _unusedWords;
00109 std::set<int> _notIndexedWords;
00110 std::set<int> _removedIndexedWords;
00111 };
00112
00113 }