J'ai un programme OpenCV en C++ qui prend un grand Mat et retourne un vecteur de plus petits Mats, que j'essaie d'utiliser dans MatLab en utilisant mex (en particulier mexOpenCV de ici: https://github.com/kyamagu/mexopencv). Je peux récupérer un seul Mat dans les plhs [0] simplement avec plhs [0] = MxArray (theMats [0]) par exemple, mais comment puis-je retourner le vecteur entier?Comment retourner un vecteur de OpenCV C++ Mats à MatLab via mex
Merci!
#include "mexopencv.hpp"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// Check number of arguments
nargchk(nlhs<=1 && nrhs==1);
// Convert mxArray to cv::Mat
cv::Mat mat = MxArray(prhs[0]).toMat();
std::vector<cv::Mat> theMats;
int ySize = 400;
int xSize = 400;
int yStride = ySize;
int xStride = xSize;
int cols = (mat.cols-xSize)/xStride + 1;
int rows = (mat.rows-ySize)/yStride + 1;
for (int i=0; i<cols; i++){
for (int j=0; j<rows; j++){
cv::Rect crop(cv::Point(i*xStride,j*yStride),
cv::Point(i*xStride+xSize, j*yStride+ySize));
theMats.push_back(mat(crop));
}
}
// Convert cv::Mat back to mxArray
plhs[0] = MxArray(theMats[0]); //I want theMats, not just theMats[0]
}