Conversion from IplImage* to cv::MAT
61,376
Solution 1
here is a good solution
Mat(const IplImage* img, bool copyData=false);
Solution 2
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.
Solution 3
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
Solution 4
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);
Solution 5
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 :)
Related videos on Youtube
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
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
-
Barshan Das about 11 yearsRegarding cvMat and Mat , see the link: stackoverflow.com/questions/11037798/…
-
-
Andrey Kamaev about 11 yearsThis constructor will be completely removed from the API in the next major update of the library
-
Antonio over 10 years@AndreyKamaev Are you sure about this? Shouldn't this constructor be marked as deprecated then?
-
Micka about 8 yearsafaik newer OpenCV versions (3.x) don't support this constructor anymore.
-
Hossam Badri about 8 yearsIt has been a long time so :)
-
Micka about 8 yearsa curent question was linked to this answer, so I just wanted to mention that :)
-
mojiiz almost 8 years@Micka For OpenCV 3.x you can use cv::cvarrToMat(ipl*). Below answer was answered this issue :)
-
M_N1 almost 4 yearsOriginal source for this answer...