ocl::
KNearestNeighbour
: public ocl::
CvKNearest
¶The class implements KNearest Neighbors model as described in the beginning of this section.
Computes the weighted sum of two arrays.
class CV_EXPORTS KNearestNeighbour: public CvKNearest
{
public:
KNearestNeighbour();
~KNearestNeighbour();
bool train(const Mat& trainData, Mat& labels, Mat& sampleIdx = Mat().setTo(Scalar::all(0)),
bool isRegression = false, int max_k = 32, bool updateBase = false);
void clear();
void find_nearest(const oclMat& samples, int k, oclMat& lables);
private:
/* hidden */
};
Trains the model.
bool ocl::KNearestNeighbour::
train
(const Mat& trainData, Mat& labels, Mat& sampleIdx=Mat().setTo(Scalar::all(0)), bool isRegression=false, int max_k=32, bool updateBase=false)¶Parameters: 


The method trains the KNearest model. It follows the conventions of the generic CvStatModel::train()
approach with the following limitations:
CV_ROW_SAMPLE
data layout is supported.is_regression=false
) or ordered ( is_regression=true
).var_idx
) and missing measurements are not supported.Finds the neighbors and predicts responses for input vectors.
void ocl::KNearestNeighbour::
find_nearest
(const oclMat& samples, int k, oclMat& lables)¶Parameters: 


Finds centers of clusters and groups input samples around the clusters.
double ocl::
kmeans
(const oclMat& src, int K, oclMat& bestLabels, TermCriteria criteria, int attemps, int flags, oclMat& centers)¶Parameters: 


For each samples in source
, find its closest neighour in centers
.
void ocl::
distanceToCenters
(const oclMat& src, const oclMat& centers, Mat& dists, Mat& labels, int distType=NORM_L2SQR)¶Parameters: 


The method is a utility function which maybe used for multiple clustering algorithms such as Kmeans.