Ask Your Question

Revision history [back]

You can get the centroid by passing an additional output parameter (exactly what are you are doing right now...)

Mat centers(clusterCount, 1, points.type());

kmeans(points, clusterCount, labels,
  TermCriteria( cv::TermCriteria::EPS+cv::TermCriteria::MAX_ITER, 10, 1.0),
  3, cv::KMEANS_PP_CENTERS, centers);

For setting the initial centroids, you can pass the KMEANS_USE_INITIAL_LABELS-flag. The centroids are then computed from your given labels. I don't know a direct way of setting the centroid.