Ask Your Question

segmentation fault on iplimage

asked 2014-06-13 08:49:51 -0500

hvn gravatar image


I have this piece of code that compiles well but ends with segmentation fault:

IplImage* image_in;    
cv_bridge::CvImagePtr cv_im_ptr;   
image_in->imageData = (char *) cv_im_ptr->;

So far I fail to see why this goes wrong. Hints and suggestions welcome.

edit retag flag offensive close merge delete


you probably should use a cv::Mat instead of an IplImage

really, they're trying to get rid of the c-api since 2010

berak gravatar imageberak ( 2014-06-13 09:00:16 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-13 09:01:52 -0500

unxnut gravatar image

You have not allocated any space for your image_in. Replace the first line with:

IplImage * image_in = new IplImage;

But it will be better to use cv::Mat instead of IplImage.

edit flag offensive delete link more



hey, not new, but cvCreateImage(...) , it's C !

berak gravatar imageberak ( 2014-06-13 09:07:26 -0500 )edit

OK, thanks. However, both with "new IplImage" and "IplImage* image_in = cvCreateImage(cvSize(320, 240), 8, 1);" I get the same error.

hvn gravatar imagehvn ( 2014-06-13 14:46:01 -0500 )edit

The manual says that you should not assign imageData directly. Please check Also, you seem to be modifying the address pointed to by imageData. That is not correct either.

unxnut gravatar imageunxnut ( 2014-06-13 16:18:04 -0500 )edit

Thank you.

hvn gravatar imagehvn ( 2014-06-15 05:21:35 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-06-13 08:49:51 -0500

Seen: 234 times

Last updated: Jun 13 '14