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 xml
I don't know what I miss.
can someone please help me?
svm->load("images/svm_filename.xml");
this is wrong, and won't do anything useful. please use:(it's a static function, which returns a new object)
@berak I'm the one who post the question but I can't sign in with sleo, that's why I create a new user account.
the function is working fine and gives satisfying result in C++. but I want to load the xml file in Android like this
using the OpenCV4Android library (OpenCV 3.2)
if you think, we can help with your account problem: issue here
can it be, your c++ and java versions are slightly "out-of-sync" and disagree, where to look for e.g. the svm type in the xml ? (there were bugs/changes in early 3.2 there)
would updating the src code, and building the android wrappers locally be an option for you ?
@sleo5 finally how you load xml?