Ask Your Question

IplImage* conversion problem

asked 2014-06-18 08:38:22 -0500

hvn gravatar image

updated 2014-06-18 13:18:08 -0500


After lots of trying, I'm left with 1 issue:

IplImage* imageThresh = cvCreateImage(cvGetSize(image), 8, 1);
Mat imageThreshMat = Mat(imageThresh, false);
<some code that needs Mat>
imageThresh->imageData = (char *);
return imageThresh;

The return gives error: "could not convert ‘imageThresh’ from ‘IplImage* {aka _IplImage*}’ to ‘IplImage {aka _IplImage}’". How can I do this conversion ?

Code after change:

<omitting code needing Mat>
imageHSV->imageData = (char *);
*imageThresh = imageThreshMat.operator _IplImage();
return imageThresh;

This still gives the conversion error with return.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2014-06-18 08:53:34 -0500

unxnut gravatar image

You can convert the Mat image to IplImage by using the following:

*imageThresh = imageThreshMat.operator IplImage();
edit flag offensive delete link more


Thank for your response. Tried this as well, but it doesn't solve the problem with the return either. BTW, which conversion do you recommend, using operator or (char *) ?

hvn gravatar imagehvn ( 2014-06-18 09:03:30 -0500 )edit

Using operator is the recommended conversion. After using the conversion, you do not have to copy the data.

unxnut gravatar imageunxnut ( 2014-06-18 09:35:24 -0500 )edit

I changed the conversion to your recommendation. Could you give a reason why the conversion error remains ?

hvn gravatar imagehvn ( 2014-06-18 10:29:54 -0500 )edit

Without knowing all the details of the code, it is hard to say but I'll hazard a guess that you need to change the second statement above to: Mat imageThreshMat = Mat(imageThresh, true);

unxnut gravatar imageunxnut ( 2014-06-18 10:42:54 -0500 )edit

Unfortunately that makes no difference. I also tried to define IplImage* outside the function and use "new IplImage" instead of cvCreateImage, but that doesn't help. Any more suggestions ?

hvn gravatar imagehvn ( 2014-06-18 12:10:20 -0500 )edit

Can you try to cvReleaseImage before copying back into it with the Mat operator?

unxnut gravatar imageunxnut ( 2014-06-18 12:28:39 -0500 )edit

Do you mean cvReleaseImage before "imageThresh->imageData" or before "Mat imageThreshMat = Mat(imageThresh, false);" ?

hvn gravatar imagehvn ( 2014-06-18 12:44:50 -0500 )edit

imageThresh-&gt;imageData is unnecessary because you would copy into imageThresh using operator IplImage(). You should do cvReleaseImage ( imageThresh ); just before you copy with the operator.

unxnut gravatar imageunxnut ( 2014-06-18 12:51:27 -0500 )edit

You are releasing imageHSV and overwriting imageThresh. You need to release imageThresh.

unxnut gravatar imageunxnut ( 2014-06-18 13:37:48 -0500 )edit

I will use imageThresh later, hence the return. Isn't releasing freeing the memory and so throwing it away ?

hvn gravatar imagehvn ( 2014-06-18 15:10:31 -0500 )edit

Question Tools


Asked: 2014-06-18 08:38:22 -0500

Seen: 443 times

Last updated: Jun 18 '14