Ask Your Question
0

IplImage* conversion problem

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

hvn gravatar image

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

Hi,

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 *) imageThreshMat.data;
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 *) imageHSVMat.data;
cvReleaseImage(&imageHSV);
*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
1

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

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

Comments

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 -0600 )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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

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

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

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

hvn gravatar imagehvn ( 2014-06-18 12:44:50 -0600 )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 -0600 )edit

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

unxnut gravatar imageunxnut ( 2014-06-18 13:37:48 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 1,372 times

Last updated: Jun 18 '14