2013-04-08 31 views
1

我正在尝试使用CvNormalBayesClassifier来训练我的程序以了解皮肤像素颜色。我有一套训练图像和响应图像。响应图像呈黑白色,皮肤区域标记为白色。下面是我的代码,正在更新OpenCV CvNormalBayesClassifier

CvNormalBayesClassifier classifier; 
for (int i = 0; i < numFiles; i++) { 

    string trainFile = "images/" + int2str(i) + ".jpg"; 
    string responseFile = "images/" + int2str(i) + "_mask.jpg"; 

    Mat trainData = imread(trainFile, 1); 
    Mat responseData = imread(responseFile, CV_LOAD_IMAGE_GRAYSCALE); 

    trainData = trainData.reshape(1, trainData.rows * trainData.cols); 
    responseData = responseData.reshape(0, responseData.rows * responseData.cols); 

    trainData.convertTo(trainData, CV_32FC1); 
    responseData.convertTo(responseData, CV_32FC1); 

    classifier.train(trainData, responseData, Mat(), Mat(), i != 0); 
} 

但是,它给了以下错误,

The function/feature is not implemented (In the current implementation the new training data must have absolutely the same set of class labels as used in the original training data) in CvNormalBayesClassifier::train

非常感谢。

回答

0

好吧,我发现问题是黑白图像已被压缩,因此包含值范围从0-255。因此,其他图像中可能会有新的类别标签。

为了解决此问题,使用阈值,使值全部变为0或255

0

如错误消息所述,您无法根据新类标签“更新”分类器。正态贝叶斯分类器学习高斯混合来表示训练数据。如果您突然开始添加新标签,则此混合模型将不再正确,并且必须从头开始学习新模型。

+0

但只有在响应图像两种颜色,所以我只有两个班吧?怎么会有新班?谢谢。 – Lucius 2013-04-09 01:40:29

+0

@李银功对不起,我一定误解了你的问题。我以为你知道有不同的班级标签,并试图“更新”学习模型。 – 2013-04-10 18:10:26