2012-06-16 24 views
4

我使用下列調用OpenCV的函數來執行K-means算法:錯誤在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 *的圖像* b *格式。

但上面的線,在編譯時,顯示了以下錯誤:

`CV_KMEANS_USE_INITIAL_LABELS' undeclared (first use in this function) 

too many arguments to function `cvKMeans2' 

這將是非常有益的,如果有人能指出哪裏是錯的,特別是它說KMEANS_USE_INITIAL_LABELS未申報的第一個錯誤。

在此先感謝!

回答

2

opencv doccvKMeans2

標誌 - 可以是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); 
+0

沒有用。現在它顯示「CV_KMEANS_USE_INITIAL_LABELS」未申報(首次在此功能中使用)「。 – Koustav

+0

@Koustav:剛纔注意到你將use_initial_labels的值賦給了rng參數,而不是標誌。我的編輯答案中的建議有幫助嗎? – Junuxx

+0

對不起,還沒有運氣。 – Koustav