Opencv Contour Error

asked 2013-06-27 06:27:14 -0600

burakim gravatar image

I want to find contours of my image then I want to draw contour using openCV. I'm using VS 2012 and OpenCV 2.4.5 I wrote sample code about finding contours and drawing contours. Bu I stacked that horrible error :) For any help I will be appreciated

void MyClass::findContoursAndDraw(cv::Mat image,int b,int g,int r)
{
findContours(image,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
for(int i=0;i<contours.size();i++)
{
int size=cv::contourArea(contours[i]);
if(size>500)
{
    printf("%i \n",size);
    drawContours(originalTemp,contours,i,cv::Scalar(b,g,r),2,8);        
}

}
}

void MyClass::findContoursAndDrawFilled(cv::Mat image,int b,int g,int r)
{
findContours(image,contours,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
for(int i=0;i<contours.size();i++)
{
    int size=cv::contourArea(contours[i]);
    if(size>3000)
   {
    printf("%i \n",size);
    drawContours(originalImg,contours,i,cv::Scalar(b,g,r));     
}

}
}

My threshold and other necessary function works very well. But My program stacked at finding contour and drawcontour function. Says that:

 Unhandled exception at 0x00B3A52A (opencv_imgproc245d.dll) in OpencvTest.exe: 
 0xC0000005: Access violation reading location 0xCDCDCDCD
edit retag flag offensive close merge delete

Comments

Hi, i was wondering if you found how to solve the problem? I have a similar problem, which is caused by the function findContours returning some empty or uninitialized memory (the 0xCDCDCDCD code) in the contours vector. Thanks.

Alejandro gravatar imageAlejandro ( 2013-11-20 08:23:25 -0600 )edit