How to convert CvMat* to cv::Mat in OpenCV3.0

Toshi picture Toshi · May 25, 2015 · Viewed 8.8k times · Source

In opencv2.4.10 which I used before, conversion from CvMat* to cv::Mat can be done as below.

CvMat *src = ...;
cv::Mat dst;
dst = cv::Mat(src);

However, in opencv3.0 rc1 cannot convert like this. In certain website, this conversion can be done as below.

CvMat* src = ...;
cv::Mat dst;
dst = cv::Mat(src->rows, src->cols, src->type, src->data.*);

If type of src is 'float', the last argument is 'src->data.fl'.

Why constructor of cv::Mat is decreased? Or are there some methods about conversion from CvMat* to cv::Mat?

Answer

hariprasad picture hariprasad · Jan 5, 2016
CvMat* matrix;
Mat M0 = cvarrToMat(matrix);

OpenCV provided this function instead of Mat(matrix).

Note: In OpenCV 3.0 they wrapped up all the constructors which convert old-style structures (cvmat, IPLImage) to the new-style Mat into this function.