OpenCV 5.0.0-pre
Open Source Computer Vision
Loading...
Searching...
No Matches

#include <opencv2/features.hpp>

Collaboration diagram for cv::ANNIndex:

Public Types

enum  Distance {
  DIST_EUCLIDEAN ,
  DIST_MANHATTAN ,
  DIST_ANGULAR ,
  DIST_HAMMING ,
  DIST_DOTPRODUCT
}
 Metrics used to calculate the distance between two feature vectors. More...
 

Public Member Functions

virtual ~ANNIndex ()=default
 
virtual void addItems (InputArray features)=0
 Add feature vectors to index.
 
virtual void build (int trees=-1)=0
 Build the index.
 
virtual int getItemNumber ()=0
 Return the number of feature vectors in the index.
 
virtual int getTreeNumber ()=0
 Return the number of trees in the index.
 
virtual void knnSearch (InputArray query, OutputArray indices, OutputArray dists, int knn, int search_k=-1)=0
 Performs a K-nearest neighbor search for given query vector(s) using the index.
 
virtual void load (const String &filename, bool prefault=false)=0
 Loads (mmaps) an index from disk.
 
virtual void save (const String &filename, bool prefault=false)=0
 Save the index to disk and loads it. After saving, no more vectors can be added.
 
virtual bool setOnDiskBuild (const String &filename)=0
 Prepare to build the index in the specified file instead of RAM (execute before adding items, no need to save after build)
 
virtual void setSeed (int seed)=0
 Initialize the random number generator with the given seed. Only necessary to pass this before adding the items. Will have no effect after calling build() or load().
 

Static Public Member Functions

static Ptr< ANNIndexcreate (int dim, ANNIndex::Distance distType=ANNIndex::DIST_EUCLIDEAN)
 Creates an instance of annoy index class with given parameters.
 

Member Enumeration Documentation

◆ Distance

Metrics used to calculate the distance between two feature vectors.

Enumerator
DIST_EUCLIDEAN 
DIST_MANHATTAN 
DIST_ANGULAR 
DIST_HAMMING 
DIST_DOTPRODUCT 

Constructor & Destructor Documentation

◆ ~ANNIndex()

virtual cv::ANNIndex::~ANNIndex ( )
virtualdefault

Member Function Documentation

◆ addItems()

virtual void cv::ANNIndex::addItems ( InputArray features)
pure virtual
Python:
cv.ANNIndex.addItems(features) -> None

Add feature vectors to index.

Parameters
featuresMatrix containing the feature vectors to index. The size of the matrix is num_features x feature_dimension.

◆ build()

virtual void cv::ANNIndex::build ( int trees = -1)
pure virtual
Python:
cv.ANNIndex.build([, trees]) -> None

Build the index.

Parameters
treesNumber of trees in the index. If not provided, the number is determined automatically in a way that at most 2x as much memory as the features vectors take is used.

◆ create()

static Ptr< ANNIndex > cv::ANNIndex::create ( int dim,
ANNIndex::Distance distType = ANNIndex::DIST_EUCLIDEAN )
static
Python:
cv.ANNIndex.create(dim[, distType]) -> retval
cv.ANNIndex_create(dim[, distType]) -> retval

Creates an instance of annoy index class with given parameters.

Parameters
dimThe dimension of the feature vector.
distTypeMetric to calculate the distance between two feature vectors, can be DIST_EUCLIDEAN, DIST_MANHATTAN, DIST_ANGULAR, DIST_HAMMING, or DIST_DOTPRODUCT.

◆ getItemNumber()

virtual int cv::ANNIndex::getItemNumber ( )
pure virtual
Python:
cv.ANNIndex.getItemNumber() -> retval

Return the number of feature vectors in the index.

◆ getTreeNumber()

virtual int cv::ANNIndex::getTreeNumber ( )
pure virtual
Python:
cv.ANNIndex.getTreeNumber() -> retval

Return the number of trees in the index.

◆ knnSearch()

virtual void cv::ANNIndex::knnSearch ( InputArray query,
OutputArray indices,
OutputArray dists,
int knn,
int search_k = -1 )
pure virtual
Python:
cv.ANNIndex.knnSearch(query, knn[, indices[, dists[, search_k]]]) -> indices, dists

Performs a K-nearest neighbor search for given query vector(s) using the index.

Parameters
queryThe query vector(s).
indicesMatrix that will contain the indices of the K-nearest neighbors found, optional.
distsMatrix that will contain the distances to the K-nearest neighbors found, optional.
knnNumber of nearest neighbors to search for.
search_kThe maximum number of nodes to inspect, which defaults to trees x knn if not provided.

◆ load()

virtual void cv::ANNIndex::load ( const String & filename,
bool prefault = false )
pure virtual
Python:
cv.ANNIndex.load(filename[, prefault]) -> None

Loads (mmaps) an index from disk.

Parameters
filenameFilename of the index to be loaded.
prefaultIf prefault is set to true, it will pre-read the entire file into memory (using mmap with MAP_POPULATE). Default is false.

◆ save()

virtual void cv::ANNIndex::save ( const String & filename,
bool prefault = false )
pure virtual
Python:
cv.ANNIndex.save(filename[, prefault]) -> None

Save the index to disk and loads it. After saving, no more vectors can be added.

Parameters
filenameFilename of the index to be saved.
prefaultIf prefault is set to true, it will pre-read the entire file into memory (using mmap with MAP_POPULATE). Default is false.

◆ setOnDiskBuild()

virtual bool cv::ANNIndex::setOnDiskBuild ( const String & filename)
pure virtual
Python:
cv.ANNIndex.setOnDiskBuild(filename) -> retval

Prepare to build the index in the specified file instead of RAM (execute before adding items, no need to save after build)

Parameters
filenameFilename of the index to be built.

◆ setSeed()

virtual void cv::ANNIndex::setSeed ( int seed)
pure virtual
Python:
cv.ANNIndex.setSeed(seed) -> None

Initialize the random number generator with the given seed. Only necessary to pass this before adding the items. Will have no effect after calling build() or load().

Parameters
seedThe given seed of the random number generator. Its value should be within the range of uint32_t.

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