Finds the centers of clusters and groups the input samples around the clusters.
Parameters: 


The function kmeans implements a kmeans algorithm that finds the centers of clusterCount clusters and groups the input samples around the clusters. On output, contains a 0based cluster index for the sample stored in the row of the samples matrix.
The function returns the compactness measure, which is computed as
after every attempt; the best (minimum) value is chosen and the corresponding labels and the compactness value are returned by the function. Basically, the user can use only the core of the function, set the number of attempts to 1, initialize labels each time using some custom algorithm and pass them with ( flags = KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best (mostcompact) clustering.
Splits an element set into equivalency classes.
Parameters: 


The generic function partition implements an algorithm for splitting a set of elements into one or more equivalency classes, as described in http://en.wikipedia.org/wiki/Disjointset_data_structure . The function returns the number of equivalency classes.
This section documents OpenCV’s interface to the FLANN library. FLANN (Fast Library for Approximate Nearest Neighbors) is a library that contains a collection of algorithms optimized for fast nearest neighbor search in large datasets and for high dimensional features. More information about FLANN can be found in [muja_flann_2009] .
The FLANN nearest neighbor index class.
namespace flann
{
class Index
{
public:
Index(const Mat& features, const IndexParams& params);
void knnSearch(const vector<float>& query,
vector<int>& indices,
vector<float>& dists,
int knn,
const SearchParams& params);
void knnSearch(const Mat& queries,
Mat& indices,
Mat& dists,
int knn,
const SearchParams& params);
int radiusSearch(const vector<float>& query,
vector<int>& indices,
vector<float>& dists,
float radius,
const SearchParams& params);
int radiusSearch(const Mat& query,
Mat& indices,
Mat& dists,
float radius,
const SearchParams& params);
void save(std::string filename);
int veclen() const;
int size() const;
};
}
Constructs a nearest neighbor search index for a given dataset.
Parameters: 


Performs a Knearest neighbor search for a given query point using the index.
Parameters: 


struct SearchParams {
SearchParams(int checks = 32);
};
 checks The number of times the tree(s) in the index should be recursively traversed. A
higher value for this parameter would give better search precision, but also take more time. If automatic configuration was used when the index was created, the number of checks required to achieve the specified precision was also computed, in which case this parameter is ignored.
Performs a Knearest neighbor search for multiple query points.
Parameters: 


Performs a radius nearest neighbor search for a given query point.
Parameters: 


Performs a radius nearest neighbor search for multiple query points.
Parameters: 


Saves the index to a file.
Parameter:  filename – The file to save the index to 

Clusters the given points by constructing a hierarchical kmeans tree and choosing a cut in the tree that minimizes the cluster’s variance.
Parameters: 


The function returns the number of clusters computed.