Class ANNIndex
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
Approximate nearest neighbor index backed by Annoy (OpenCV 5), a modern alternative to FLANN.
public class ANNIndex : CvPtrObject, IDisposable
- Inheritance
-
ANNIndex
- Implements
- Inherited Members
Methods
AddItems(InputArray)
Adds feature vectors to the index.
public void AddItems(InputArray features)
Parameters
featuresInputArrayMatrix containing the feature vectors to index (num_features x feature_dimension).
Build(int)
Builds the index.
public void Build(int trees = -1)
Parameters
treesintNumber of trees in the index. -1 determines the number automatically.
Create(int, ANNIndexDistance)
Creates an instance of the Annoy index with the given parameters.
public static ANNIndex Create(int dim, ANNIndexDistance distType = ANNIndexDistance.Euclidean)
Parameters
dimintThe dimension of the feature vector.
distTypeANNIndexDistanceMetric used to calculate the distance between two feature vectors.
Returns
GetItemNumber()
Returns the number of feature vectors in the index.
public int GetItemNumber()
Returns
GetTreeNumber()
Returns the number of trees in the index.
public int GetTreeNumber()
Returns
KnnSearch(InputArray, OutputArray, OutputArray, int, int)
Performs a K-nearest neighbor search for the given query vector(s) using the index.
public void KnnSearch(InputArray query, OutputArray indices, OutputArray dists, int knn, int searchK = -1)
Parameters
queryInputArrayThe query vector(s).
indicesOutputArrayOutput matrix that will contain the indices of the K-nearest neighbors found.
distsOutputArrayOutput matrix that will contain the distances to the K-nearest neighbors found.
knnintNumber of nearest neighbors to search for.
searchKintThe maximum number of nodes to inspect; defaults to trees x knn when -1.
Load(string, bool)
Loads (mmaps) an index from disk.
public void Load(string filename, bool prefault = false)
Parameters
filenamestringFilename of the index to be loaded.
prefaultboolIf true, pre-reads the entire file into memory.
Save(string, bool)
Saves the index to disk. After saving, no more vectors can be added.
public void Save(string filename, bool prefault = false)
Parameters
filenamestringFilename of the index to be saved.
prefaultboolIf true, pre-reads the entire file into memory.
SetOnDiskBuild(string)
Prepares to build the index in the specified file instead of in RAM (call before adding items; no need to save after build).
public bool SetOnDiskBuild(string filename)
Parameters
filenamestringFilename of the index to be built.
Returns
- bool
True on success.
SetSeed(int)
Initializes the random number generator with the given seed. Only effective before adding items / calling build() or load().
public void SetSeed(int seed)
Parameters
seedintThe seed of the random number generator.