'Problem with deprecated conversion from cv::mat to IplImage
I know there were already questions like this in the past but all the answers seem not to work anymore since some functions are deprecated so I hope you can help me.
That's what I try to do :
IplImage* image = 0;
Mat frame;
image = cvCloneImage(&(IplImage)frame);
Basically I get an error because of the last line :
E0312 no suitable user-defined conversion from "cv::Mat" to "IplImage" exists
By the way if instead there is a manual way to convert Mat to IplImage it's also great for me.
PS : I'm trying to use an old code so it doesn't bother me if Mat is the new standard in OpenCV and not advised using IplImage.
PS2 : If there is an old version of OpenCV that can do this without errors it's also OK.
Thank you!
Solution 1:[1]
I try to make hand-crafted conversion. In my enviroment it works well (OpenCV 2.4.9).
Be carefull with pix_type
variable value.
Mat frame_gray = imread("img.bmp");
int pix_type = IPL_DEPTH_8U;
IplImage* img = cvCreateImage(frame_gray.size(), pix_type , frame_gray.channels());
img->imageData = reinterpret_cast<char*>(frame_gray.data);
img->widthStep = frame_gray.step;
Solution 2:[2]
On modern versions of OpenCV (3.9 and later) you can use function cvIplImage:
Mat matImage;
IplImage iplImage = cvIplImage(matImage);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Prog_rez |
Solution 2 | Elmir |