Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV K-Means (kmeans2)

I'm using Opencv's K-means implementation to cluster a large set of 8-dimensional vectors. They cluster fine, but I can't find any way to see the prototypes created by the clustering process. Is this even possible? OpenCV only seems to give access to the cluster indexes (or labels).

If not I guess it'll be time to make my own implementation!

like image 303
n00dle Avatar asked Oct 30 '09 16:10

n00dle


2 Answers

I can't say I used OpenCV's implementation of Kmeans, but if you have access to the labels given to each instance, you can simply get the centroids by calculating the average vector of instances belong to each of the clusters.

like image 184
Amro Avatar answered Oct 13 '22 04:10

Amro


As of (at least) OpenCV 2.0, there is the way to retrieve cluster centers (see the latest argument):

double kmeans( const Mat& samples, int clusterCount, Mat& labels,
  TermCriteria termcrit, int attempts,
  int flags, Mat* centers );

http://opencv.willowgarage.com/documentation/cpp/clustering_and_search_in_multi-dimensional_spaces.html#cv-kmeans

like image 30
Roman Shapovalov Avatar answered Oct 13 '22 04:10

Roman Shapovalov