【问题标题】:Error in K-means algorithmK-means 算法中的错误
【发布时间】:2012-06-19 08:11:25
【问题描述】:

我使用以下对 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 undeclared,那将非常有帮助。

提前致谢!

【问题讨论】:

    标签: c opencv k-means


    【解决方案1】:

    来自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);
    

    【讨论】:

    • 没用。现在它显示“`CV_KMEANS_USE_INITIAL_LABELS' undeclared (first use in this function)”。
    • @Koustav:刚刚注意到您将 use_initial_labels 值赋予 rng 参数而不是标志。我编辑的答案中的建议有帮助吗?
    • @Koustav:您使用的是哪个版本的 OpenCV?在 OpenCV 1 中,cvKmeans2 只接受 4 个参数。额外的 5 个可选参数仅在 v2.x 中。这似乎是我现在最有可能出现问题的原因。它还可以解释您遇到的第二个错误。
    • 是的,明白了!我实际上使用的是 OpenCV 1.1,所以我想这就是原因。非常感谢队友!! :) :)
    猜你喜欢
    • 2013-07-03
    • 2019-02-19
    • 2018-10-11
    • 2010-12-05
    • 2017-04-20
    • 2013-04-22
    • 2016-04-15
    • 2011-09-15
    相关资源
    最近更新 更多