2017-08-21 148 views
0
FileStorage fs; 
fs.open("SVM.xml" , FileStorage::READ); 
Mat SVM_TrainningData; 
Mat SVM_Classes;  
fs["TrainingData"] >>SVM_TrainningData; 
fs["classes"] >>SVM_Classes; 

Ptr<ml::SVM> svm = ml::SVM::create(); 
svm->setType(ml::SVM::C_SVC); 
svm->setKernel(ml::SVM::LINEAR); 
//I have do the data type test here, The data type is ok. 
#if _DEBUG 
CV_Assert(SVM_TrainningData.type() == CV_32F || SVM_TrainningData.type() == CV_32S); 
if (!SVM_Classes.empty()) 
{ 
    CV_Assert(SVM_Classes.type() == CV_32F || SVM_Classes.type() == CV_32S); 
} 
#endif 

svmClassifier->train(SVM_TrainningData, ml::ROW_SAMPLE,SVM_Classes); //crash here 

回答

0

檢查您的數據是否包含NaN或無限值。它崩潰NaN和infinte值。如果是,請將它們替換爲0值。