2 l740450789 l740450789 于 2014.12.20 11:03 提问

opencv中的kmeans函数
LBPimage是一个3通道的灰度图像。通过kmeans函数之后,分的两类,labels的各个分量都是0,只有第一个和最后一个元素是1.请问大神们,错在哪里。

Mat LBPimage=LBP(imgs);
int nl = LBPimage.rows;
int nc = LBPimage.cols;
Mat points;
points.create(nc*nl, 1, CV_32FC1);
int n = 0;
for (int i = 0; i < nl; i++)
{
    for (int j = 0; j < nc; j++)
    {
        points.at<int>(n,0) = (int)LBPimage.at<Vec3b>(i, j)[0];
        n++;
    }
}
Mat labels;
Mat centers;
kmeans(points, 2, labels, TermCriteria(CV_TERMCRIT_EPS,10000,0.01), 50, KMEANS_PP_CENTERS, centers);
Csdn user default icon
上传中...
上传图片
插入图片