Object Serialization in C++ for storing the OpenCV's SVM object [OpenCV 3.1.0]

asked 2017-04-08 15:40:56 -0500

dohnjoe gravatar image

updated 2017-04-10 04:58:45 -0500

So it is common knowledge that due to a bug in OpenCV when you try to load a non-linear kernel SVM after saving it you get an error.

Refer here for more: https://github.com/opencv/opencv/issu...

People HAVE gotten the SVM to load but were unable to obtain the same result (classifier data was corrupted after loading). I tried testing this by writing my own svmloader function.

Ptr<SVM> svmloader(const String& filepath)
    FileStorage fs;
    fs.open(filepath, FileStorage::READ);

    Ptr<SVM> svm = Algorithm::read<SVM>(fs.getFirstTopLevelNode());
    return svm;

This works but I can as of now confirm that I've tested model pre and post loading and the results seem worse post-loading. That is after you train a classifier and you test it, it will be fine but if you save it and load it again it will get effed up.

So I think I want to use C++'s Object serialization to solve this problem. How can I write arbitary objects to a file and then read from that file?

Also can someone confirm if the above bug has been fixed in OpenCV 3.2.0 ,I COULD NOT FIND ANYTHING IN THE RELEASE NOTES


edit retag flag offensive close merge delete


There is a guy explicitly proving (in the issue you referenced yourself) that it is working as it should right?

StevenPuttemans gravatar imageStevenPuttemans ( 2017-04-10 05:01:22 -0500 )edit