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,
145 const cv::Mat & features,
146 bool useDistanceL1 =
false,
147 float rebalancingFactor = 2.0f);
164 const std::vector<unsigned char> & indexData,
166 const cv::Mat & features,
167 bool useDistanceL1 =
false,
168 float rebalancingFactor = 2.0f,
169 std::string * errorMsg = NULL);
172 const unsigned char * indexData,
173 size_t indexDataSize,
175 const cv::Mat & features,
176 bool useDistanceL1 =
false,
177 float rebalancingFactor = 2.0f,
178 std::string * errorMsg = NULL);
195 std::vector<unsigned int>
addPoints(
const cv::Mat & features);
222 const cv::Mat & query,
229 int cores = 1)
const;
247 const cv::Mat & query,
248 std::vector<std::vector<size_t> > & indices,
249 std::vector<std::vector<float> > & dists,
251 int maxNeighbors = 0,
255 int cores = 1)
const;
259 NanoFlannIndex * nanoIndex_;
260 unsigned int nextIndex_;
264 float rebalancingFactor_;
269 std::map<int, cv::Mat> addedDescriptors_;
270 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, int cores=1) 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.
static void setDeterministicSeed(bool enable)
Make the randomized rtflann indexes the same from one run to another.
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, int cores=1) const
Search the k nearest neighbors of each query.