Ask Your Question

sLeo's profile - activity

2017-06-07 05:59:41 -0600 asked a question Android App don't load SVM trained (on C++) file for recognition

I've trained a svm using OpenCV 3.2 on C++. Just like that

// Set up SVM's parameters
Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setC(100);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

// Train the SVM with given parameters
Ptr<TrainData> td = TrainData::create(training_mat, ROW_SAMPLE, labelsMat);
svm->train(td);
svm->save("images/svm_filename.xml");

Now I try to load the produced xml file on Android, I use the OpenCV4Android (OpenCV 3.2). But the load function seems not to work. the load function SVM svm = SVM.load("svm_filename.xml"); just throws an exception (the path is correct because I included the xml file in the App).

cv::Exception: /build/master_pack-android/opencv/modules/ml/src/svm.cpp:2123: error: (-212) Missing or invalid SVM type in function void cv::ml::SVMImpl::read_params(const cv::FileNode&)

On C++ everything's fine, the load function works fine

svm->load("images/svm_filename.xml");

I don't understand why the svm type is mentioned as missing. When I take a look a the XML file the svm type is C_SVC. here is a part of the xmlimage description

I don't know what I miss.

can someone please help me?