Ask Your Question
0

How do I load a pre-trained SVM using C++?

asked 2016-11-20 06:30:16 -0600

erikvdplas gravatar image

I've trained an SVM model using OpenCV for Python on my Mac. Now we're trying to use OpenCV for C++ to load the model inside our iOS app so we can make predictions. We've already tackled an issue regarding an extra XML tag that the C++ lib doesn't expect and therefore throws an error (https://github.com/opencv/opencv/issu...). However when we try to load our XML into an SVM we get a EXC_BAD_ACCESS (code = 1) error... This is the code we use:

NSString *path = [[NSBundle mainBundle] pathForResource:@"model" ofType:@"xml"];
const char* cPath = [path cStringUsingEncoding:NSMacOSRomanStringEncoding];

cv::FileStorage read((const cv::String)cPath, cv::FileStorage::READ);
Ptr<SVM> my_svm = cv::ml::SVM::create();

my_svm->read(read.root());

Is this a bug? Or am I doing something wrong?

edit retag flag offensive close merge delete

Comments

You should not use read directly but go for the load function as explained before...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-11-21 08:52:07 -0600 )edit

I made a new thread about this: http://answers.opencv.org/question/11...

tomgekeerd gravatar imagetomgekeerd ( 2016-12-02 17:31:41 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-01-03 20:01:55 -0600

vincentliu gravatar image

Try: StatModel::load<svm>("YourSVMFile");

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-11-20 06:30:16 -0600

Seen: 1,775 times

Last updated: Nov 20 '16