OpenCV
3.4.13pre
Open Source Computer Vision

The FLANN nearest neighbor index class. This class is templated with the type of elements for which the index is built. More...
#include <opencv2/flann.hpp>
Public Types  
typedef Distance::ResultType  DistanceType 
typedef Distance::ElementType  ElementType 
Public Member Functions  
GenericIndex (const Mat &features, const ::cvflann::IndexParams ¶ms, Distance distance=Distance())  
Constructs a nearest neighbor search index for a given dataset. More...  
~GenericIndex ()  
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 ¶ms) 
Performs a Knearest neighbor search for a given query point using the index. More...  
void  knnSearch (const Mat &queries, Mat &indices, Mat &dists, int knn, const ::cvflann::SearchParams ¶ms) 
int  radiusSearch (const std::vector< ElementType > &query, std::vector< int > &indices, std::vector< DistanceType > &dists, DistanceType radius, const ::cvflann::SearchParams ¶ms) 
Performs a radius nearest neighbor search for a given query point using the index. More...  
int  radiusSearch (const Mat &query, Mat &indices, Mat &dists, DistanceType radius, const ::cvflann::SearchParams ¶ms) 
void  save (String filename) 
int  size () const 
int  veclen () const 
The FLANN nearest neighbor index class. This class is templated with the type of elements for which the index is built.
Distance
functor specifies the metric to be used to calculate the distance between two points. There are several Distance
functors that are readily available:
cv::cvflann::L2_Simple  Squared Euclidean distance functor. This is the simpler, unrolled version. This is preferable for very low dimensionality data (eg 3D points)
cv::flann::L2  Squared Euclidean distance functor, optimized version.
cv::flann::L1  Manhattan distance functor, optimized version.
cv::flann::MinkowskiDistance  The Minkowsky distance functor. This is highly optimised with loop unrolling. The computation of squared root at the end is omitted for efficiency.
cv::flann::MaxDistance  The max distance functor. It computes the maximum distance between two vectors. This distance is not a valid kdtree distance, it's not dimensionwise additive.
cv::flann::HammingLUT  Hamming distance functor. It counts the bit differences between two strings using a lookup table implementation.
cv::flann::Hamming  Hamming distance functor. Population count is performed using library calls, if available. Lookup table implementation is used as a fallback.
cv::flann::Hamming2  Hamming distance functor. Population count is implemented in 12 arithmetic operations (one of which is multiplication).
cv::flann::DNAmmingLUT  Adaptation of the Hamming distance functor to DNA comparison. As the four bases A, C, G, T of the DNA (or A, G, C, U for RNA) can be coded on 2 bits, it counts the bits pairs differences between two sequences using a lookup table implementation.
cv::flann::DNAmming2  Adaptation of the Hamming distance functor to DNA comparison. Bases differences count are vectorised thanks to arithmetic operations using standard registers (AVX2 and AVX512 should come in a near future).
cv::flann::HistIntersectionDistance  The histogram intersection distance functor.
cv::flann::HellingerDistance  The Hellinger distance functor.
cv::flann::ChiSquareDistance  The chisquare distance functor.
cv::flann::KL_Divergence  The KullbackLeibler divergence functor.
Although the provided implementations cover a vast range of cases, it is also possible to use a custom implementation. The distance functor is a class whose operator()
computes the distance between two features. If the distance is also a kdtree compatible distance, it should also provide an accum_dist()
method that computes the distance between individual feature dimensions.
In addition to operator()
and accum_dist()
, a distance functor should also define the ElementType
and the ResultType
as the types of the elements it operates on and the type of the result it computes. If a distance functor can be used as a kdtree distance (meaning that the full distance between a pair of features can be accumulated from the partial distances between the individual dimensions) a typedef is_kdtree_distance
should be present inside the distance functor. If the distance is not a kdtree distance, but it's a distance in a vector space (the individual dimensions of the elements it operates on can be accessed independently) a typedef is_vector_space_distance
should be defined inside the functor. If neither typedef is defined, the distance is assumed to be a metric distance and will only be used with indexes operating on generic metric distances.
typedef Distance::ResultType cv::flann::GenericIndex< Distance >::DistanceType 
typedef Distance::ElementType cv::flann::GenericIndex< Distance >::ElementType 
cv::flann::GenericIndex< Distance >::GenericIndex  (  const Mat &  features, 
const ::cvflann::IndexParams &  params,  
Distance  distance = Distance() 

) 
Constructs a nearest neighbor search index for a given dataset.
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: 
cv::flann::GenericIndex< Distance >::~GenericIndex  (  ) 

inline 

inline 
void cv::flann::GenericIndex< Distance >::knnSearch  (  const std::vector< ElementType > &  query, 
std::vector< int > &  indices,  
std::vector< DistanceType > &  dists,  
int  knn,  
const ::cvflann::SearchParams &  params  
) 
Performs a Knearest neighbor search for a given query point using the index.
query  The query point 
indices  Vector that will contain the indices of the Knearest neighbors found. It must have at least knn size. 
dists  Vector that will contain the distances to the Knearest neighbors found. It must have at least knn size. 
knn  Number of nearest neighbors to search for. 
params  SearchParams 
void cv::flann::GenericIndex< Distance >::knnSearch  (  const Mat &  queries, 
Mat &  indices,  
Mat &  dists,  
int  knn,  
const ::cvflann::SearchParams &  params  
) 
int cv::flann::GenericIndex< Distance >::radiusSearch  (  const std::vector< ElementType > &  query, 
std::vector< int > &  indices,  
std::vector< DistanceType > &  dists,  
DistanceType  radius,  
const ::cvflann::SearchParams &  params  
) 
Performs a radius nearest neighbor search for a given query point using the index.
query  The query point. 
indices  Vector that will contain the indices of the nearest neighbors found. 
dists  Vector that will contain the distances to the nearest neighbors found. It has the same number of elements as indices. 
radius  The search radius. 
params  SearchParams 
This function returns the number of nearest neighbors found.
int cv::flann::GenericIndex< Distance >::radiusSearch  (  const Mat &  query, 
Mat &  indices,  
Mat &  dists,  
DistanceType  radius,  
const ::cvflann::SearchParams &  params  
) 

inline 

inline 

inline 