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
You can use the Matlab bridge from opencv contrib. All you need from Opencv Contrib is to copy contrib/modules/matlab/include/opencv2/matlab folder into the include/opencv2 folder.
along with the Matlab Compiler Runtime (just libmx.lib, libmex.lib and libmat.lib).
MATFile *pmat = matOpen(filename, "r");
if (pmat == NULL)
{
cerr << "Error opening file " << filename << endl;
}
else
{
int numVars;
char** namePtr = matGetDir(pmat, &numVars);
cout << filename << " contains vars " << endl;
for (int idx = 0; idx < numVars; idx++)
{
std::cout << " " << namePtr[idx] << " ";
mxArray* m = matGetVariable(pmat, namePtr[idx]);
matlab::MxArray mArray(m);
cv::bridge::Bridge bridge(mArray);
cv::Mat mat = bridge.toMat();
// do something with opencv Mat
}
}