OpenCV: cv::flann::GenericIndex< Distance > Class Template Reference

| OpenCV 3.4.2 Open Source Computer Vision

Public Types | Public Member Functions | List of all members
cv::flann::GenericIndex< Distance > Class Template Reference
Clustering and Search in Multi-Dimensional Spaces

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"`

## Public Types
typedef Distance::ResultType | DistanceType
typedef Distance::ElementType | ElementType

## Public Member Functions
| GenericIndex (const Mat &features, const ::cvflann::IndexParams &params, 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 &params)
| Performs a K-nearest 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 &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 Description

### 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.

## Member Typedef Documentation

## ◆ DistanceType

template<typename Distance >

typedef Distance::ResultType cv::flann::GenericIndex< Distance >::DistanceType

## ◆ ElementType

template<typename Distance >

typedef Distance::ElementType cv::flann::GenericIndex< Distance >::ElementType

## Constructor & Destructor Documentation

## ◆ GenericIndex()

template<typename Distance >

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.

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:

- 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 );
  };

## ◆ ~GenericIndex()

template<typename Distance >

cv::flann::GenericIndex< Distance >::~GenericIndex | ( |  | ) |

## Member Function Documentation

## ◆ getIndexParameters()

template<typename Distance >

const ::cvflann::IndexParams* cv::flann::GenericIndex< Distance >::getIndexParameters | ( |  | ) |
| inline

## ◆ getParameters()

template<typename Distance >

::cvflann::IndexParams cv::flann::GenericIndex< Distance >::getParameters | ( |  | ) |
| inline

## ◆ knnSearch() [1/2]

template<typename Distance >

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 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

## ◆ knnSearch() [2/2]

template<typename Distance >

void cv::flann::GenericIndex< Distance >::knnSearch | ( | const Mat & | queries,
|  | Mat & | indices,
|  | Mat & | dists,
|  | int | knn,
|  | const ::cvflann::SearchParams & | params
| ) |  |

## ◆ radiusSearch() [1/2]

template<typename Distance >

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
| ) |  |

## ◆ radiusSearch() [2/2]

template<typename Distance >

int cv::flann::GenericIndex< Distance >::radiusSearch | ( | const Mat & | query,
|  | Mat & | indices,
|  | Mat & | dists,
|  | DistanceType | radius,
|  | const ::cvflann::SearchParams & | params
| ) |  |

## ◆ save()

template<typename Distance >

void cv::flann::GenericIndex< Distance >::save | ( | String | filename | ) |
| inline

## ◆ size()

template<typename Distance >

int cv::flann::GenericIndex< Distance >::size | ( |  | ) | const
| inline

## ◆ veclen()

template<typename Distance >

int cv::flann::GenericIndex< Distance >::veclen | ( |  | ) | const
| inline

The documentation for this class was generated from the following file:

- flann/include/opencv2/flann.hpp