template<typename Distance>
class cv::flann::GenericIndex< Distance >
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 Minkowski 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 AVX-512 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 chi-square distance functor.
cv::flann::KL_Divergence - The Kullback-Leibler 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 kd-tree 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 kd-tree 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 kd-tree 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.