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
  • 137
  • 9

3 Answers3

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
  • 137
  • 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,738
  • 1
  • 4
  • 7
0
//opencv 4.5.2

IplImage* IplImage_img = cvCreateImage(cvSize(img.cols, img.rows), 8, 1);

cv::Mat MatImg(img.rows, img.cols, CV_8U, cv::Scalar(0));

MatImg = cv::cvarrToMat(IplImage_img);

img.copyTo(MatImg);
halfelf
  • 9,737
  • 13
  • 54
  • 63
MIK
  • 1
  • 1