1

I am traying to convert a cv::Mat to IplImage in pc with this caracteristcs:

  • opencv: 3.4.14
  • OS: Win 10
  • code: c++

An example of the differents options:

cv::Mat MBin = cv::Mat::zeros(cv::Size(64, 64), CV_32FC1);

IplImage* image0= new IplImage(MBin);
IplImage image1 = MBin;
IplImage* image2 = cvCloneImage(&(IplImage)MBin);

IplImage* image3;
image3 = cvCreateImage(cvSize(MBin.cols, MBin.rows), 8, 3);
IplImage image4 = MBin;
cvCopy(&image4, image3);

Where imageX appears produces the title error.

SSR
  • 139
  • 9

2 Answers2

2

This is the only solution, which doesn't generate compiler error:

#include <opencv2/core/types_c.h>

Mat Img = imread("1.jpg");

IplImage IBin_2 = cvIplImage(MBin);
IplImage* IBin = &IBin_2;
SSR
  • 139
  • 9
0

Before opencv3.x, Mat has a constructor Mat(const IplImage* img, bool copyData=false);. But in opencv3.x, Mat(const IplImage* img, bool copyData=false); constructor is canceled.

So, you could refer to the following example to convert Mat to IplImage.

//Mat—>IplImage
//EXAMPLE:
//shallow copy:
Mat Img=imread("1.jpg");
IplImage* pBinary = &IplImage(Img);
//For a deep copy, just add another copy of the data:
IplImage *input = cvCloneImage(pBinary)

Also, you could refer to this link for more information.

Barrnet Chou
  • 1,586
  • 1
  • 3
  • 7