Convert OpenCV Mat to IplImage *

I have a pointer to an image:

IplImage *img; 

which has been converted to Mat

 Mat mt(img); 

Then Mat sent to a function that references Mat as the input void f(Mat &m);

 f(mt); 

Now I want to copy the Mat data into the original image.

Do you have any suggestions?

Best ali

+6
source share
3 answers

Your answer can be found in the documentation: http://opencv.willowgarage.com/documentation/cpp/c++_cheatsheet.html

Edit:

The first half of the first area of ​​code really talks about the copy constructor that you already have.

The second half of the first area of ​​code answers your question. For clarification, illustrated below.

 //Convert to IplImage or CvMat, no data copying IplImage ipl_img = img; CvMat cvmat = img; // convert cv::Mat -> CvMat 
+2
source

In the following case:

 double algorithm(IplImage* imgin) { //blabla return erg; } 

I use the following method of calling a function:

 cv::Mat image = cv::imread("image.bmp"); double erg = algorithm(&image.operator IplImage()); 

I did some tests and saw how the image object will manage memory. The IplImage() operator IplImage() build the header for IplImage . Maybe this can be useful?

+1
source

You can use this form:

Your code:

plImage * img;

Mother mt (img);

e (t);

Now copy the Mat data to the original image.

img-> imageData = (char *) mt.data;

You can also copy data instead of a pointer:

memcpy (mt.data, img-> imageData, (mt.rows * mt.cols));

(mt.rows * mt.cols) is the size you should use to copy all mt data to img.

I hope I helped

0
source

Source: https://habr.com/ru/post/888934/


All Articles