我正在尝试使用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
非常感谢。

最佳答案

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

09-04 02:18