[英]Store in hard disk a CvSVM object
我已经在opencv中为面部创建了一个SVM检测器。 我想分开训练和预测的过程。 因此,我想找到一种在我的硬盘中存储CvSVM SVM对象的方法,以便在不需要再次训练新模型的情况下随时访问它。 这样,我可以通过从硬盘加载SVM对象来使用预测方法。 这在Matlab中非常简单,但是如何在opencv c ++中成功呢?
使用加载和保存功能以加载和保存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;
}
也很简单。 这是一个CvStatModel
,因此它带有save
和load
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.