我使用以下调用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未声明.
提前致谢 !
最佳答案 从
opencv doc开始cvKMeans2:
flags – Can be 0 or CV_KMEANS_USE_INITIAL_LABELS.
你遗漏了CV_.
编辑:还要注意termcrit和flags之间应该有两个参数,所以你要跳过尝试或rng.尝试
cvKMeans2(points, count, &clusters, cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ), 1, 0, CV_KMEANS_USE_INITIAL_LABELS, centers);