Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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: github dot com slash opencv slash opencv slash issues slash 5054

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

Any help is GREATLY APPRECIATED folks

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

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: github dot com slash opencv slash opencv slash issues slash 5054https://github.com/opencv/opencv/issues/5054

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

Any help is GREATLY APPRECIATED folks