OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Fri, 14 Aug 2015 23:24:38 -0500K means questionhttp://answers.opencv.org/question/68648/k-means-question/Hey everybody,
I'm currently in the process of clustering a set of points into different sections. Though, the k means algorithm requires me to explicitly set the number of clusters to divide the set of points in. Is there an alternative algorithm, where I can pass in a set of points and a maximum distance, which divides point clusters from each other? What I would like to have returned is a list of clusters of yet unknown size, containing a sub-set of points.
I would be very thankful for any directions.
Thanks,
MarcelFri, 14 Aug 2015 13:18:51 -0500http://answers.opencv.org/question/68648/k-means-question/Answer by berak for <p>Hey everybody,</p>
<p>I'm currently in the process of clustering a set of points into different sections. Though, the k means algorithm requires me to explicitly set the number of clusters to divide the set of points in. Is there an alternative algorithm, where I can pass in a set of points and a maximum distance, which divides point clusters from each other? What I would like to have returned is a list of clusters of yet unknown size, containing a sub-set of points. </p>
<p>I would be very thankful for any directions.</p>
<p>Thanks,
Marcel</p>
http://answers.opencv.org/question/68648/k-means-question/?answer=68655#post-id-68655yes, you can use [partition](http://docs.opencv.org/ref/master/d5/d38/group__core__cluster.html#ga2037c989e69b499c1aa271419f3a9b34) with a distance functor:
struct Dist {
bool operator()(const Point& a, const Point &b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)) < 15;
}
};
vector<Point> input = ...;
vector<int> labels;
partition(input, labels, Dist());Fri, 14 Aug 2015 23:24:38 -0500http://answers.opencv.org/question/68648/k-means-question/?answer=68655#post-id-68655