Conversion from IplImage* to cv::MAT
Asked Answered
S

5

25

I searched to convert an IplImage* to Mat, but all answers were about the conversion to cvMat.

How, can I do it? and what is the difference between Mat and cvMat?

Thanks in advance

Sluice answered 10/4, 2013 at 11:53 Comment(1)
Regarding cvMat and Mat , see the link: #11038298Porush
T
14

here is a good solution

Mat(const IplImage* img, bool copyData=false);
Teratology answered 22/4, 2013 at 9:44 Comment(4)
afaik newer OpenCV versions (3.x) don't support this constructor anymore.Hipolitohipp
It has been a long time so :)Teratology
a curent question was linked to this answer, so I just wanted to mention that :)Hipolitohipp
@Hipolitohipp For OpenCV 3.x you can use cv::cvarrToMat(ipl*). Below answer was answered this issue :)Nilgai
S
45

For the records: taking a look at core/src/matrix.cpp it seems that, indeed, the constructor cv::Mat(IplImage*) has disappeared.

But I found this alternative:

IplImage * ipl = ...;
cv::Mat m = cv::cvarrToMat(ipl);  // default additional arguments: don't copy data.
Seldom answered 15/6, 2015 at 16:1 Comment(1)
Original source for this answer...Recluse
T
14

here is a good solution

Mat(const IplImage* img, bool copyData=false);
Teratology answered 22/4, 2013 at 9:44 Comment(4)
afaik newer OpenCV versions (3.x) don't support this constructor anymore.Hipolitohipp
It has been a long time so :)Teratology
a curent question was linked to this answer, so I just wanted to mention that :)Hipolitohipp
@Hipolitohipp For OpenCV 3.x you can use cv::cvarrToMat(ipl*). Below answer was answered this issue :)Nilgai
C
11

The recommended way is the cv::cvarrToMat function

cv::Mat - is base data structure for OpenCV 2.x

CvMat - is old C analog of cv::Mat

Cussed answered 10/4, 2013 at 11:56 Comment(0)
S
5

Check out the Mat documentation.

// converts old-style IplImage to the new matrix; the data is not copied by default
Mat(const IplImage* img, bool copyData=false);
Sherr answered 10/4, 2013 at 11:57 Comment(2)
This constructor will be completely removed from the API in the next major update of the libraryCussed
@AndreyKamaev Are you sure about this? Shouldn't this constructor be marked as deprecated then?Verulamium
R
4
  • cv::Mat or Mat, both are same.

  • Mat has a operator CvMat() so simple assignment works

Convert Mat to CvMat

Mat mat = ---------;
CvMat cvmat = mat;

Convert CVMat to Mat

Mat dst = Mat(cvmat, true);  

Convert Mat to IplImage*

> For Single Channel

IplImage* image = cvCloneImage(&(IplImage)mat); 

> For Three Channel

IplImage* image = cvCreateImage(cvSize(mat.cols, mat.rows), 8, 3);
IplImage ipltemp = mat;
cvCopy(&ipltemp, image);

Hope this helps you. Cheers :)

Riccio answered 12/1, 2016 at 4:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.