Toshi
Toshi

Reputation: 103

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

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?

Upvotes: 10

Views: 10191

Answers (2)

hariprasad
hariprasad

Reputation: 858

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.

Upvotes: 12

Abc
Abc

Reputation: 824

In order to convert CvMat* to Mat you have to do like this:

cv::Mat dst(src->rows, src->cols, CV_64FC1, src->data.fl);

Upvotes: 1

Related Questions