Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Loading cv::RTrees from memory

I use OpenCv for image classification. After training I've saved model to *.yaml.gz. Then I've added this file to embedded resources. Now I need to load model from resource, but OpenCv allows only loading from files or strings.

HMODULE ModuleHandle;

void LoadBinaryResource(int resId, void** data, int& size)
{
    HRSRC resource = ::FindResource(ModuleHandle, MAKEINTRESOURCE(resId), RT_RCDATA);
    HGLOBAL resourceData = ::LoadResource(ModuleHandle, resource);
    *data = ::LockResource(resourceData);
    size = ::SizeofResource(ModuleHandle, resource);
}


void LoadRTreesFromResource(int resId, cv::RTrees& forest)
{
    void* binaryData;
    int size;
    LoadBinaryResource(resId, &binaryData, size);

    // here I need to load CvStatModel from binaryData
}

Now I am forced to write data to a file and then use cv::RTres::load method.

Is there any way to load CvStatModel from memory? Or how can I serialize/deserialize model to binary format without using methods cv::RTres::save and cv::RTres::load?

Thank you!