kmeans function

(double, Mat, Mat) kmeans(
  1. InputArray data,
  2. int K,
  3. InputOutputArray bestLabels,
  4. (int, int, double) criteria,
  5. int attempts,
  6. int flags, {
  7. OutputArray? centers,
})

KMeans finds centers of clusters and groups input samples around the clusters.

For further details, please see: https://docs.opencv.org/master/d5/d38/group__core__cluster.html#ga9a34dc06c6ec9460e90860f15bcd2f88

Implementation

(double rval, Mat bestLabels, Mat centers) kmeans(
  InputArray data,
  int K,
  InputOutputArray bestLabels,
  (int, int, double) criteria,
  int attempts,
  int flags, {
  OutputArray? centers,
}) {
  centers ??= Mat.empty();
  final rval = cvRunArena<double>((arena) {
    final p = arena<ffi.Double>();
    cvRun(
      () => ccore.KMeans(
        data.ref,
        K,
        bestLabels.ref,
        TermCriteria.fromRecord(criteria).ref,
        attempts,
        flags,
        centers!.ref,
        p,
      ),
    );
    return p.value;
  });
  return (rval, bestLabels, centers);
}