Error in the K-Means Algorithm

I use the following call to the openCV function to execute the 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 a CIE L * a * b * image.

But the above line when 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 it is wrong, especially the first error, which says that KMEANS_USE_INITIAL_LABELS is not declared.

Thanks in advance!

+4
source share
1 answer

From opencv doc for cvKMeans2 :

flags - can be 0 or CV_KMEANS_USE_INITIAL_LABELS.

You left CV _ .

Edit: also note that there must be two between termcrit and flags , so you skip 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); 
+2
source

All Articles