Ask Your Question
1

opencv/findContour crashes, v2.4.4, MS visual studio 2010. edit:damaged head.

asked 2013-05-04 14:30:39 -0600

MattiasR gravatar image

updated 2013-05-06 01:40:56 -0600

edit 2: When the error message occur, I press continue and get a new error message:

Unhandled exception at 0x770540f2 in eyeTracking.exe: 0xC0000374: A heap is damaged

(A heap is damaged) is translated from swedish, so the exact line of text might be different from what you are familiar with.

--------end of edit 2.---------

edit 1: System: windows7, 64bit. --------end of edit 1.---------

I have developed a system that detects & tracks the face of a person(real time, with usb camera). From that data I want to collect parameters from the eyes (blinks for example). Everything works fine until I try to use the command findContour,

std::vector< std::vector<cv::Point> > contours;
cv::findContours( test, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE );

I've tried this for a couple of days now, but I cant figure it out how to make it work. Examples from internet doesnt work either.

Before I run the method cv::findContours() I run the following methods:

m = ~currentWebCamFrame(trackP.EyePosition(false));
cv::cvtColor(m,n, CV_RGB2GRAY);
cv::threshold(n, m, threshold-value, 255,CV_THRESH_BINARY);
cv::erode(m, n, cv::Mat(),cv::Point(-1,-1),n_erode_dilate);
cv::dilate(n, m, cv::Mat(),cv::Point(-1,-1),n_erode_dilate);

test = m.clone();

When I output the image "test" this is the result: image description

Before I run the "findContour()" I test the following:

if((!test.empty()) && (test.type() == CV_8UC1)){ };

There is no available error message from opencv, the program just crashed. I printf() some text right before and after. And it is only the text before that is visible in the console.

The message from Visual studio is:

Windows has triggered a breakpoint in eyeTracking.exe. 
This may be due to a corruption of the heap, which indicates a bug in the eyeTracking.exe or any of the DLLs it has loaded. 
This May also be due to the user pressing F12 while eyeTracking has focus.

I dont know what to do, so if there is anyone that has any idea, please let me know!

Thanks!

edit retag flag offensive close merge delete

Comments

I have the same problem in VS 2010. The problem was solved when I change option 'Use of MFC' to 'Use MFC in a Shared DLL'. But I still not understand why it could not work with static MFC dll.

AntonM gravatar imageAntonM ( 2013-12-11 07:22:44 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-05-04 14:51:12 -0600

efanucar gravatar image

Try to use a new variable of the type Mat as result of your threshold call, looks like test (which is a clone of m) is not a binary image

edit flag offensive delete link more

Comments

Thank you! I will trye that first thing in the morning. I have a question. Is itpossible to test the matrix if it is binary or not? like my IF-statement testing if it is grayscale & not empty.

MattiasR gravatar imageMattiasR ( 2013-05-04 15:11:21 -0600 )edit
MattiasR gravatar imageMattiasR ( 2013-05-04 15:13:47 -0600 )edit

It didnt work :(

MattiasR gravatar imageMattiasR ( 2013-05-05 01:34:12 -0600 )edit
0

answered 2013-05-06 01:49:38 -0600

efanucar gravatar image

Here is some code for using findContours:

using namespace cv;
using namespace std;

// ...

vector<vector<Point>> contours;
Mat imgGray, imgEdges;

// m is your input image

cvtColor(m, imgGray, CV_RGB2GRAY);
threshold(imgGray, imgEdges, threshold-value, 255, CV_THRESH_BINARY);

// erode, dilation, ...

findContours(imgEdges, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE );

You should try to make this work, because findContours is an elementary function which you will use often.

edit flag offensive delete link more
0

answered 2014-04-19 16:04:36 -0600

Y Simson gravatar image

I too had trouble with findContour. I worked around the problem using old C style cvFindContour

Here is a suggested work around

Let me know if it works for you

edit flag offensive delete link more

Comments

Hum, I tried your solution with open 3.1.0 and 2.4.11. I still have the crash. Thanks anyway

pthomet gravatar imagepthomet ( 2016-09-09 04:54:50 -0600 )edit

Question Tools

Stats

Asked: 2013-05-04 14:30:39 -0600

Seen: 3,913 times

Last updated: Apr 19 '14