2014-12-09 116 views
0

我正在嘗試使用OpenCV和SVM進行培訓。 但我有一個問題,正是這個錯誤:關於OpenCV Mat錯誤的SVM(列車數據必須是浮點矩陣)

OpenCV Error: Bad argument (train data must be floating-point matrix) in cvCheckTrainData 

我必須做的一列火車在圖像的數據集,每一個圖像具有68點(X,Y),我使用做SVM。

在開始的時候,這是我的代碼:

//for each image 
fin_land.open(str_app); assert(fin_land); 
for (int i=(0+(68*count_FOR)); i<(num_landCKplus+(68*count_FOR)); i++) { 
    fin_land >> f1; 
    fin_land >> f2; 
    int data[2] = {(int)f1, (int)f2}; 
    Mat actual(1, 2, CV_32FC1, &data); 
    trainData.push_back(actual); 
} 
// SVM 
CvSVMParams params; 
params.svm_type = CvSVM::NU_SVC; 
params.kernel_type = CvSVM::POLY;  
trainData = trainData.reshape(1, #numImage); 
SVM.train(trainData, trainLabels, Mat(), Mat(), params); 

這段代碼的問題是,我想用一個墊子用68行2列的測試,因爲每培訓類在我的SVM有2列,但我收到此錯誤:

OpenCV Error: Incorrect size of input array (Input sample must be 1-dimensional vector) in cvPreparePredictData 

如果我理解正確的,問題是,測試墊的尺寸必須是唯一的一維。所以,我認爲要修改這樣我的代碼:

//for each image 
fin_land.open(str_app); assert(fin_land); 
for (int i=(0+(68*count_FOR)); i<(num_landCKplus+(68*count_FOR)); i++) { 
    fin_land >> f1; 
    fin_land >> f1; 
    int data = (int)f1; 
    trainData.push_back(&data); 
    data = (int)f2; 
    trainData.push_back(&data); 
} 

現在每天的訓練級只有一列,因此測試的連墊,但我有一個新的錯誤,它說:

OpenCV Error: Bad argument (train data must be floating-point matrix) in cvCheckTrainData 

問題是trainingSet的新mat的類型是錯誤的? 我也不知道如何解決它...

回答

0
  • 需要浮點數據(整數和標籤),每個功能
  • 1排,每排1個標籤。

float f1,f2; 
for (int i=(0+(68*count_FOR)); i<(num_landCKplus+(68*count_FOR)); i++) { 
    fin_land >> f1; 
    fin_land >> f1; 
    trainData.push_back(f1); // pushing the 1st thing will determine the type of trainData 
    trainData.push_back(f2); 
} 

trainData = trainData.reshape(1, numItems); 
SVM.train(trainData, trainLabels, Mat(), Mat(), params); 
+0

謝謝你..似乎是確定..但現在我卡住培訓,不返回任何錯誤。我試圖等待,但隨着582 * 544訓練矩陣這似乎很奇怪,它需要這麼長時間...這可能是一個過度修復的問題? – luke88 2014-12-09 12:46:40