2011-08-23 197 views
2

我使用OpenCv创建CvNormalBayesClassifier,但是当我尝试训练它时,我收到一个错误消息。 这是我的代码:CvNormalBayesClassifier训练错误

CvMat train=cvMat(1, 32, CV_32FC1, val); 
CvMat res=cvMat(1, 1, CV_32FC1, type); 
M1.train(&train, &res); 

其中val是双阵列,并且type只是一个INT元件的阵列。 M1是我CvNormalBayesClassifier

我得到的错误是这个:

OpenCV Error: Bad argument (There is only a single class) in cvPreprocessCategoricalResponses, file /build/buildd/opencv-2.1.0/src/ml/ml_inner_functions.cpp, line 731 terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.1.0/src/ml/ml_inner_functions.cpp:731: error: (-5) There is only a single class in function cvPreprocessCategoricalResponses

中止

谢谢你的任何建议

回答

0

首先,最后一个参数cvMat功能有void*类型,因此它不知道数组的实际类型。结果没有数据转换是可能的。但是您使用的CV_32FC1常数假设为float类型,而trainres矩阵只是将int和double的位重新解释为浮点数。而你的CvNormalBayesClassifier只看到垃圾而不是真实的数据。

1

这个错误意味着你的响应数组res,是完全一致的(它必须是因为它只有元素)。无论是增加一个独特的价值,让教练来训练,或者告诉它你做一个一流的培训:

CvSVMParams params; 
params.svm_type = CvSVM::ONE_CLASS; 
M1.train(train, res, Mat(), Mat(), params); 

我没有用“ONE_CLASS”的工作,所以你可能需要给“NU “参数a值(见OpenCV SVM doc page)。另外,我不认为安培是必要的。

+0

“CvSVMParams”(和单类分类)是否仅与SVM分类器相关,而不是正态贝叶斯分类器? – DNA