Converting a .mat file from MATLAB into cv::Mat matrix in OpenCV

前端 未结 3 2008
我寻月下人不归
我寻月下人不归 2020-12-29 15:34

I have some MATLAB code that I want to migrate to OpenCV. The data that the MATLAB code uses is stored in a .mat file which is then loaded at run time.

I converted

3条回答
  •  离开以前
    2020-12-29 16:07

    Besides using XML/YAML file storages suggested by @Drodbar, you can also try cvmatio, which provides APIs to directly load MATLAB MAT files to OpenCV.

    The code will be simply like:

    #include "MatlabIO.hpp"
    #include "MatlabIOContainer.hpp"
    
    ...
    
    // load the MATLAB MAT file
    MatlabIO matio;
    bool ok = matio.open("-path-to-mat-file.mat", "r");
    if (!ok) return -1;
    
    // read all of the variables in the file
    std::vector variables;
    variables = matio.read();
    matio.close();
    
    // load the matrix by name in OpenCV style
    cv::Mat basis = matio.find(variables, "B")
    

提交回复
热议问题