//距离小于10的点归为一类
bool _EqPredicate(const Point& a, const Point& b)
{return ((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x)<10*10);
}
void ClusteringPartition()
{
Mat img(500, 500, CV_8UC3);
RNG rng(12345);
vector<Point> points;
vector<int> labels;
int sampleCount=6;
points.push_back(Point(200,200));
points.push_back(Point(200,215));
points.push_back(Point(205,200));
points.push_back(Point(400,200));
points.push_back(Point(400,205));
points.push_back(Point(405,200));
randShuffle(points, 1, &rng);
long count=partition(points, labels,_EqPredicate);
OutInfo("count",count);
img = Scalar::all(0);
for( int i = 0; i < sampleCount; i++ )
{
Point ipt = points.at(i);
circle( img, ipt, 2, CV_RGB(255,255,255), 1, LINE_AA );
}
imshow("points", img);
img = Scalar::all(0);
for( int i = 0; i < sampleCount; i++ )
{
int Idx = labels.at(i)+1;
Point ipt = points.at(i);
circle( img, ipt, 2, CV_RGB(Idx*100%255,0,0), FILLED, LINE_AA );
}
imshow("partition", img);
}