OpenCV K-Means (kmeans2)

夙愿已清 提交于 2019-12-10 03:29:01

问题


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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1650904/opencv-k-means-kmeans2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!