Ask Your Question

Segmentation fault with iplmage pointer, ROS node.

asked 2013-03-06 16:31:49 -0600

zweistein666 gravatar image

I'm trying to detect a blob on a video feed with cvBlob lib in my ROS node. I think, I made a mistake with pointers, but I can't figure out where.

Moreover, do I have to free some of this variable?

Mat& corridorProces(Mat& resultImg)
    Mat srcMat=resultImg.clone();
    cvtColor( resultImg, resultImg, CV_RGB2GRAY );
    IplImage src= resultImg.clone();
    IplImage *src_g= new IplImage(src);
    IplImage *src_g_inv=new IplImage(src);
    cvThreshold(src_g, src_g_inv,35,255, CV_THRESH_BINARY_INV);
    cvThreshold(src_g, src_g,40,255, CV_THRESH_BINARY);    
    IplImage *labelImg=cvCreateImage(cvGetSize(src_g), IPL_DEPTH_LABEL, 1);
    cvb::CvBlobs blobs;
    unsigned int result=cvb::cvLabel(src_g, labelImg, blobs);   
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-06 17:04:52 -0600

berak gravatar image

updated 2013-03-06 17:07:12 -0600

short answer: avoid Iplimage, use cv::Mat (and the corresponding cv:: functions) wherever you can ! (also, reconsider using that *very old cvblob thing).

long answer: using 'new' for IplImage is totally wrong(it will produce a new IplImage , but never reserve space for any pixels), use cvCreateImage(), and never forget to call cvReleaseImage() for anything you created like this !

edit flag offensive delete link more


thanks, I used IplImage *src_g=cvCloneImage(&src); and now its working.

zweistein666 gravatar imagezweistein666 ( 2013-03-07 07:37:34 -0600 )edit

Question Tools


Asked: 2013-03-06 16:31:49 -0600

Seen: 649 times

Last updated: Mar 06 '13