An example on K-means clustering
#include <iostream>
int main( int , char** )
{
const int MAX_CLUSTERS = 5;
{
};
for(;;)
{
int k, clusterCount = rng.
uniform(2, MAX_CLUSTERS+1);
int i, sampleCount = rng.
uniform(1, 1001);
clusterCount =
MIN(clusterCount, sampleCount);
for( k = 0; k < clusterCount; k++ )
{
Mat pointChunk = points.
rowRange(k*sampleCount/clusterCount,
k == clusterCount - 1 ? sampleCount :
(k+1)*sampleCount/clusterCount);
}
double compactness =
kmeans(points, clusterCount, labels,
for( i = 0; i < sampleCount; i++ )
{
int clusterIdx = labels.
at<
int>(i);
}
for (i = 0; i < centers.
rows; ++i)
{
}
cout << "Compactness: " << compactness << endl;
if( key == 27 || key == 'q' || key == 'Q' )
break;
}
return 0;
}