2011-08-23 111 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