Koustav
Koustav

Reputation: 743

Error in K-means algorithm

I use the following call to openCV function to perform K-means algorithm:

cvKMeans2(points, count, &clusters, cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ), 1, CV_KMEANS_USE_INITIAL_LABELS, centers);

where

image2 = cvLoadImage( "lab.jpg", 0);
points = cvCreateMat( image2->height, image2->width, CV_32FC1 );    
cvConvert(image2, points);
//count= number of clusters.
CvMat* centers; // To store the center of each cluster. (output).

lab.jpg is an image in CIE L*a*b* format.

But the above line, while compiling, shows the following errors:

`CV_KMEANS_USE_INITIAL_LABELS' undeclared (first use in this function) 

too many arguments to function `cvKMeans2' 

It would be very helpful if someone can point out where am wrong, specially the first error which says KMEANS_USE_INITIAL_LABELS undeclared.

Thanks in advance !

Upvotes: 4

Views: 552

Answers (1)

Junuxx
Junuxx

Reputation: 14251

From the opencv doc for cvKMeans2:

flags – Can be 0 or CV_KMEANS_USE_INITIAL_LABELS.

You left out CV_.

Edit: also note that there should be two arguments between termcrit and flags, so you are skipping either attempts or rng. Try

cvKMeans2(points, count, &clusters, cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ), 1, 0, CV_KMEANS_USE_INITIAL_LABELS, centers);

Upvotes: 2

Related Questions