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);
        }
        kmeans(points, clusterCount, labels,
 
        for( i = 0; i < sampleCount; i++ )
        {
            int clusterIdx = labels.
at<
int>(
i);
 
        }
        if( key == 27 || key == 'q' || key == 'Q' ) 
            break;
    }
    return 0;
}