Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting cv::Mat to IplImage*

Tags:

c++

opencv

The documentation on this seems incredibly spotty.

I've basically got an empty array of IplImage*s (IplImage** imageArray) and I'm calling a function to import an array of cv::Mats - I want to convert my cv::Mat into an IplImage* so I can copy it into the array.

Currently I'm trying this:

while(loop over cv::Mat array) {     IplImage* xyz = &(IplImage(array[i]));     cvCopy(iplimagearray[i], xyz); } 

Which generates a segfault.

Also trying:

while(loop over cv::Mat array) {     IplImage* xyz;     xyz = &array[i];     cvCopy(iplimagearray[i], xyz); } 

Which gives me a compile time error of: error: cannot convert ‘cv::Mat*’ to ‘IplImage*’ in assignment

Stuck as to how I can go further and would appreciate some advice :)

like image 341
amr Avatar asked Jan 12 '11 00:01

amr


1 Answers

cv::Mat is the new type introduce in OpenCV2.X while the IplImage* is the "legacy" image structure.

Although, cv::Mat does support the usage of IplImage in the constructor parameters, the default library does not provide function for the other way. You will need to extract the image header information manually. (Do remember that you need to allocate the IplImage structure, which is lack in your example).

like image 170
YeenFei Avatar answered Sep 29 '22 22:09

YeenFei