template class cv::flann::GenericIndex
Overview
The FLANN nearest neighbor index class. This class is templated with the type of elements for which the index is built. Moreā¦
#include <flann.hpp> template <typename Distance> class GenericIndex { public: // typedefs typedef Distance::ResultType DistanceType; typedef Distance::ElementType ElementType; // construction GenericIndex( const Mat& features, const ::cvflann::IndexParams& params, Distance distance = Distance() ); // methods const ::cvflann::IndexParams* getIndexParameters(); ::cvflann::IndexParams getParameters(); void knnSearch( const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params ); void knnSearch( const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params ); int radiusSearch( const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params ); int radiusSearch( const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& params ); void save(String filename); int size() const; int veclen() const; };
Detailed Documentation
The FLANN nearest neighbor index class. This class is templated with the type of elements for which the index is built.
Construction
GenericIndex( const Mat& features, const ::cvflann::IndexParams& params, Distance distance = Distance() )
Constructs a nearest neighbor search index for a given dataset.
LinearIndexParams When passing an object of this type, the index will perform a linear, brute-force search. :
struct LinearIndexParams : public IndexParams { };
KDTreeIndexParams When passing an object of this type the index constructed will consist of a set of randomized kd-trees which will be searched in parallel. :
struct KDTreeIndexParams : public IndexParams { KDTreeIndexParams( int trees = 4 ); };
KMeansIndexParams When passing an object of this type the index constructed will be a hierarchical k-means tree. :
struct KMeansIndexParams : public IndexParams { KMeansIndexParams( int branching = 32, int iterations = 11, flann_centers_init_t centers_init = CENTERS_RANDOM, float cb_index = 0.2 ); };
CompositeIndexParams When using a parameters object of this type the index created combines the randomized kd-trees and the hierarchical k-means tree. :
struct CompositeIndexParams : public IndexParams { CompositeIndexParams( int trees = 4, int branching = 32, int iterations = 11, flann_centers_init_t centers_init = CENTERS_RANDOM, float cb_index = 0.2 ); };
LshIndexParams When using a parameters object of this type the index created uses multi-probe LSH (by Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search by Qin Lv, William Josephson, Zhe Wang, Moses Charikar, Kai Li., Proceedings of the 33rd International Conference on Very Large Data Bases (VLDB). Vienna, Austria. September 2007) :
struct LshIndexParams : public IndexParams { LshIndexParams( unsigned int table_number, unsigned int key_size, unsigned int multi_probe_level ); };
AutotunedIndexParams When passing an object of this type the index created is automatically tuned to offer the best performance, by choosing the optimal index type (randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. :
struct AutotunedIndexParams : public IndexParams { AutotunedIndexParams( float target_precision = 0.9, float build_weight = 0.01, float memory_weight = 0, float sample_fraction = 0.1 ); };
SavedIndexParams This object type is used for loading a previously saved index from the disk. :
struct SavedIndexParams : public IndexParams { SavedIndexParams( String filename ); };
Parameters:
features | Matrix of containing the features(points) to index. The size of the matrix is num_features x feature_dimensionality and the data type of the elements in the matrix must coincide with the type of the index. |
params | Structure containing the index parameters. The type of index that will be constructed depends on the type of this parameter. See the description. |
distance | The method constructs a fast search structure from a set of features using the specified algorithm with specified parameters, as defined by params. params is a reference to one of the following class IndexParams descendants: |
Methods
void knnSearch( const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params )
Performs a K-nearest neighbor search for a given query point using the index.
Parameters:
query | The query point |
indices | Vector that will contain the indices of the K-nearest neighbors found. It must have at least knn size. |
dists | Vector that will contain the distances to the K-nearest neighbors found. It must have at least knn size. |
knn | Number of nearest neighbors to search for. |
params | SearchParams |