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

Viewed 12131

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 this .mat file into a .csv file and am then reading this data into OpenCV as a string using ifstream. I am having problems converting this string into a data-structure that I can then use in OpenCV.

Is there anyway that I can convert the .mat file / .csv file to a Mat data structure in OpenCV?

Edit: Based on the Answer I received, I was successful in reading MATLAB data into OpenCV using a YML file. This I did in a MAC environment. However, when I try to read the file with the same piece of code in a Windows environment, the file is not being read. Just wondering if anyone ran into such an issue. Below is my code snippet:

// OpenCVDemo.cpp : Defines the entry point for the console application.
// Created for build/install tutorial, Microsoft Visual Studio and OpenCV 2.4.0

#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>

using namespace cv;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{  
        cout << "Loading the basis." << endl;

        FileStorage fs1("basis.yml", FileStorage::READ);

        cv::FileNode B = fs1["B"];

        if (B.EMPTY)
        {
            cout << "File is empty or does not exist" << endl;
            return 1;
        }

        fs1["B"] >> basis;

        cout << basis.cols << endl;

        fs1.release();

            return 0;
}
3 Answers
Related