ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Segmentation fault with opencv function

asked 2013-03-06 10:26:13 -0500

updated 2014-01-28 17:15:34 -0500

ngrennan gravatar image

I'm trying to detect a blob on a video feed with cvBlob lib. 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? The problem appears in row: unsigned int result=cvb::cvLabel(src_g, labelImg, blobs);

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

Comments

This question is not related to ROS. It's better suited in cvBlob project mailing list or similar, not here.

Miquel Massot gravatar image Miquel Massot  ( 2013-03-06 10:47:28 -0500 )edit

Simply comment out all the code inside the function, and uncomment line by line until you find the one that give you a segmentation fault. It's not something related to ROS. It's a programming issue.

phbou72 gravatar image phbou72  ( 2013-03-06 17:09:16 -0500 )edit

The weird thing is that the algorithm implenented in Opencv works for 1 image, but when I try it in ROS, where the cv_brigde returns a cv::MAT() and I convert into Iplimage, I receive segmentation fault error.

zweistein gravatar image zweistein  ( 2013-03-06 18:43:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-03-07 01:36:08 -0500

I changed to: IplImage *src_g=cvCloneImage(&src); and now its working. I dont understand why I got some times empty packages but now there is no more segmentation fault.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-06 10:26:13 -0500

Seen: 1,976 times

Last updated: Mar 07 '13