kmeans

Description

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

Signature

cv2.kmeans(data, K, bestLabels, criteria, attempts, flags[, centers]) → retval, bestLabels, centers

Parameters

Explanation

The function kmeans implements a k-means algorithm that finds the centers of K clusters and groups the input samples around the clusters. As an output, bestLabels[i] contains a 0-based cluster index for the sample stored in the \(i^{th}\) row of the samples matrix.

The function returns retVal, the compactness measure that is computed as $$\sum_i \| \text{samples}_i - \text{centers}_{\text{labels}_i} \|^2$$ after every attempt. The best (minimum) value is chosen and the corresponding labels and the compactness value are returned by the function.

Notes


References

Created with OpenCV 4.4.0