28#ifndef CORELIB_SRC_FLANNINDEX_H_
29#define CORELIB_SRC_FLANNINDEX_H_
31#include "rtabmap/core/rtabmap_core_export.h"
33#include <opencv2/opencv.hpp>
77 FLANN_INDEX_LINEAR = 0,
78 FLANN_INDEX_KDTREE = 1,
79 FLANN_INDEX_KDTREE_SINGLE = 4,
86 NANOFLANN_INDEX_KDTREE_SINGLE = 100,
130 const cv::Mat & features,
131 bool useDistanceL1 =
false,
132 float rebalancingFactor = 2.0f);
149 const std::vector<unsigned char> & indexData,
151 const cv::Mat & features,
152 bool useDistanceL1 =
false,
153 float rebalancingFactor = 2.0f,
154 std::string * errorMsg = NULL);
157 const unsigned char * indexData,
158 size_t indexDataSize,
160 const cv::Mat & features,
161 bool useDistanceL1 =
false,
162 float rebalancingFactor = 2.0f,
163 std::string * errorMsg = NULL);
180 std::vector<unsigned int>
addPoints(
const cv::Mat & features);
206 const cv::Mat & query,
212 bool sorted =
true)
const;
230 const cv::Mat & query,
231 std::vector<std::vector<size_t> > & indices,
232 std::vector<std::vector<float> > & dists,
234 int maxNeighbors = 0,
237 bool sorted =
true)
const;
241 NanoFlannIndex * nanoIndex_;
242 unsigned int nextIndex_;
246 float rebalancingFactor_;
251 std::map<int, cv::Mat> addedDescriptors_;
252 std::list<int> removedIndexes_;
Nearest neighbor index over a set of features.
bool loadIndex(const unsigned char *indexData, size_t indexDataSize, flann_algorithm_t algorithm, const cv::Mat &features, bool useDistanceL1=false, float rebalancingFactor=2.0f, std::string *errorMsg=NULL)
Load an index from a raw buffer, see the overload above.
std::vector< unsigned char > serializeIndex(bool computeChecksum=true) const
Serialize the index, to be given back to loadIndex()
void radiusSearch(const cv::Mat &query, std::vector< std::vector< size_t > > &indices, std::vector< std::vector< float > > &dists, float radius, int maxNeighbors=0, int checks=32, float eps=0.0, bool sorted=true) const
Search the neighbors of each query within a radius.
size_t memoryUsed() const
void release()
Drop the index and everything it holds, back to the state of a new one.
size_t indexedFeatures() const
void removePoint(unsigned int index)
Remove an indexed feature, by the index addPoints() gave for it.
bool loadIndex(const std::vector< unsigned char > &indexData, flann_algorithm_t algorithm, const cv::Mat &features, bool useDistanceL1=false, float rebalancingFactor=2.0f, std::string *errorMsg=NULL)
Load an index serialized by serializeIndex(), releasing any previous one.
flann_algorithm_t
The index structure built by buildIndex()
std::vector< unsigned int > addPoints(const cv::Mat &features)
Add features to the index.
void buildIndex(flann_algorithm_t algorithm, const cv::Mat &features, bool useDistanceL1=false, float rebalancingFactor=2.0f)
Build the index over the given features, releasing any previous one.
void knnSearch(const cv::Mat &query, cv::Mat &indices, cv::Mat &dists, int knn, int checks=32, float eps=0.0, bool sorted=true) const
Search the k nearest neighbors of each query.