K-means算法出错

时间:2012-06-16 14:59:06

标签: c opencv k-means

我使用以下调用openCV函数来执行K-means算法:

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

,其中

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是CIE L * a * b *格式的图像。

但上述行在编译时会显示以下错误:

`CV_KMEANS_USE_INITIAL_LABELS' undeclared (first use in this function) 

too many arguments to function `cvKMeans2' 

如果有人可以指出哪里出错,那将是非常有帮助的,尤其是第一个错误,即KMEANS_USE_INITIAL_LABELS未声明。

提前致谢!

1 个答案:

答案 0 :(得分:2)

来自cvKMeans2的{​​{3}}:

  

flags - 可以是0或CV_KMEANS_USE_INITIAL_LABELS。

你遗漏了 CV _

修改:还要注意termcritflags之间应该有两个参数,因此您要跳过attemptsrng。尝试

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