Ask Your Question

Revision history [back]

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

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/issues/6572). 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?