Load OpenCV ML (SVM) from line

I am currently developing a machine learning based texture classification algorithm primarily to support vector machines (SVMs). I was able to get very good results on my test data and now want to use SVM in a production environment.

Production in my case means it will run across multiple desktop and mobile platforms (e.g. Android, iOS) and always somewhere deep in native threads. For reasons of software structure and platform access policies, I cannot access the filesystem from where I am using SVM. However, my infrastructure supports reading files in an environment where file system access is provided, and routes the contents of the file as std :: string to the SVM part of my application.

The standard procedure for setting up SVM is to use filenames, and OpenCV reads directly from the file:

cv::SVM _svm;
_svm.load("/home/<usrname>/DEV/TrainSoftware/trained.cfg", "<trainSetName>");

      

I want this (basically reading from a file elsewhere and passing the file content as a string to the SVM):

cv::SVM _svm;
std::string trainedCfgContentStr="<get the content here>";
_svm.loadFromString(trainedCfgContentStr, "<trainSetName>") // This method is desired

      

I couldn't find anything in the docs or the OpenCV source as it is possible, but it won't be the first OpenCV feature not documented or widely known there. Of course, I could hack the OpenCV source code and cross-compile on each of my target platforms, but I'll try to avoid that because it's a heck of a lot of work, besides I'm sure I'm not the first with this problem.

Any ideas (also non-traditional) and / or hints are highly appreciated!

+3


source to share


1 answer


if you stick with the C ++ api it's pretty simple, FileStorage can read from memory:

string data_string; //containing xml/yml data
FileStorage fs( data_string, FileStorage::READ | FileStorage::MEMORY);
svm.read(fs.getFirstTopLevelNode()); // or the node with your trainset

      



(unfortunately not showing java)

+1


source







All Articles