I want to send a Matrix to Matlab using "engine.h" in c++ code. The fact is that I have the data inside a cv::Mat, and I need to sent a mxArray. I tried to use this expression but it doesn´t work:
cv::Mat _priorP;
_priorP = Mat::eye(13, 13, CV_32FC1);
mxArray *mat;
mat = mxCreateDoubleMatrix(13, 13, mxREAL);
memcpy(mxGetPr(mat),_priorP.data, 13*13*sizeof(double));
Anybody knows the correct way to do the conversion? Any help would be apreciated. Thanks.
EDIT
I found this way: https://stackoverflow.com/a/8848711/744859
This thread shows how to convert a
CvMat
tomxArray
. Even though it's not exactly the conversion code you are looking for, it's pretty close.This is a simple conversion and you should be able to adjust the code to work with
cv::Mat
instead ofCvMat
. If you can't, a quick hack is to convert yourcv::Mat
data toCvMat
and then use the code below as is (taken from the link I suggested):