10

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?

Toshi
  • 103
  • 1
  • 5

2 Answers2

12
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.

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
hariprasad
  • 838
  • 1
  • 8
  • 16
1

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);
mpromonet
  • 11,326
  • 43
  • 62
  • 91
Abc
  • 824
  • 2
  • 7
  • 20