2014-01-30 3 views
0

opencv에서 얼굴 용 SVM 탐지기를 생성했습니다. 기차의 과정을 분리하고 예측하고 싶습니다. 따라서 열차를 다시 사용하지 않고도 새 모델을 열 때마다 하드 디스크 CvSVM SVM 객체에 액세스 할 수있는 방법을 찾고 싶습니다. 이 방법으로 하드 디스크에서 SVM 객체를로드하는 것만으로 예측 방법을 사용할 수 있습니다. 이것은 Matlab에서 매우 간단합니다. 그러나 opencv C++에서 어떻게 성공할 수 있습니까?하드 디스크에 CvSVM 객체를 저장하십시오.

로드 및 저장 기능을 사용하여 SVM 모델을로드하고 저장하면 munmap_chunk() :: invalid 포인터 메시지 (glibc가 감지 됨) 메시지가 표시됩니다.

CvSVM SVM = detect.SVMtrain("dbpath/"); 
    SVM.save("svmTrain.xml", 0); 

    cout <<"Detection system in progress progress...\n"; 
    string pathFile = databasePath+ imageFilename; 
    vector<float> confidence; 
    detections = detect.detection(pathFile); 
    CvSVM SVM; 
    SVM.load("svmTrain.xml",0); 
    confidence = detect.SVMpredict(detections.at(0), SVM); 
    //cout << "confidence is: " << confidence.at(0) << endl; 

위의 코드를 실행했을 때 위 메시지가 나타납니다. 문제는 svmpredict 함수에 있습니다. 그리고 SVMpredict 함수 :

vector<float> Detection::SVMpredict(Mat image, CvSVM SVM){ 


vector<float> res; 

//Mat image = imread(fileName,0); //Read as a gray image 
//cvtColor(sampleMat, sampleMat, CV_BGR2GRAY); 
image = eigenfacesExtraction(image); 
image.convertTo(image, CV_32FC1); // <-- Convert to CV_32F for matrix mult 

float response = SVM.predict(image); res.push_back(response); 
float val = SVM.predict(image,true); res.push_back(val); 
cout << "svm result: "<< response <<" val: "<< val << endl; 

return res; 

} 

답변

1

똑같이. CvStatModel이므로 saveload 방법이 제공됩니다.

+0

그래서 SVM.load (".. .xml"); // 저장 –

+1

저장 및로드 할 수 있습니다. 예, 그렇습니다. 또는 .yaml IIRC. – MSalters

+0

svmpredict 계산 후에 load를 사용할 때 mun_map_chunk() invalid pointer가 감지되었습니다. –

관련 문제