# Revision history [back]

### findContours throws exception intermittently - 2.4.5

We are using version 2.4.5 (x64 Release/Windows/VS2012/VC11) and call findContours() for each image we process, but seemingly randomly, it will thrown an unhandled exception. We saw this problem a couple of months ago, and we could not reproduce it and at the same time haven't seen it since then. It just started happening randomly when none of the code around this bit of processing has changed at all.

In our software, we've registered a callback to write out a memory dump in the event that an unhandled exception happens, and here is the stack trace:

STACK_TEXT:
0000000050289d90 000007fefadade25 : 000007feeabe9ec0 000000005028b1b8 0000000000000100 0000000050289e80 : KERNELBASE!RaiseException+0x39
0000000050289e60 0000000077c9d561 : 0000000000000000 000000005028c030 0000000000000000 0000000000000000 : msvcr110!_CxxCallCatchBlock+0x161
0000000050289f30 000007feeaa9f3ae : 0000000077d603d0 00000000ec06faa0 000000005028c920 0000000000000013 : ntdll!RcFrameConsolidation+0x3
000000005028c730 000007feeaa9adad : 000000005028ccb8 000000005028ccb8 0000000000000001 000000005028cb50 : opencv_imgproc245!cvFindContours+0x3de [d:\downloads\opencv_2_4_5\opencv\modules\imgproc\src\contours.cpp @ 1688]
000000005028c8e0 000007fef1e1f89e : 000000000032aae2 0000000000000000 0000000000000000 0000000000000000 : opencv_imgproc245!cv::findContours+0x18d [d:\downloads\opencv_2_4_5\opencv\modules\imgproc\src\contours.cpp @ 1713]


Function where this is called from--edgeImage is always computed the same way for each image buffer we process and is of grayscale type. We zero it out first and then call Canny() with it passed in as a second parameter. I can share more of that code if necessary, but we do not see "edge image type to be passed..." in our logging.

void FindFeaturePoints(cv::Mat& edgeImage) const
{
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;

if (edgeImage.type() != CV_8U)
_logger->Fatal("Edge image type to be passed to findContours is NOT grayscale!");

findContours(edgeImage, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0) );
}


The line 1688 of contours.cpp is:

do
{
count++;
contour = cvFindNextContour( scanner );
}
while( contour != 0 ); //1688


(which WinDbg can be one line off on, and this means it's actually something in cvFindNextContour())

I'm just not sure why this would happen randomly--it seems to occur once every several million or so images we process. Again, we've been using the same bit of code around this and haven't seen the problem in months.

Any help is greatly appreciated, especially with taking the stack trace addresses and applying them to what might be going on in the actual findContours() function.

 2 retagged sturkmen 6772 ●3 ●48 ●79 https://github.com/stu...

### findContours throws exception intermittently - 2.4.5

We are using version 2.4.5 (x64 Release/Windows/VS2012/VC11) and call findContours() for each image we process, but seemingly randomly, it will thrown an unhandled exception. We saw this problem a couple of months ago, and we could not reproduce it and at the same time haven't seen it since then. It just started happening randomly when none of the code around this bit of processing has changed at all.

In our software, we've registered a callback to write out a memory dump in the event that an unhandled exception happens, and here is the stack trace:

STACK_TEXT:
0000000050289d90 000007fefadade25 : 000007feeabe9ec0 000000005028b1b8 0000000000000100 0000000050289e80 : KERNELBASE!RaiseException+0x39
0000000050289e60 0000000077c9d561 : 0000000000000000 000000005028c030 0000000000000000 0000000000000000 : msvcr110!_CxxCallCatchBlock+0x161
0000000050289f30 000007feeaa9f3ae : 0000000077d603d0 00000000ec06faa0 000000005028c920 0000000000000013 : ntdll!RcFrameConsolidation+0x3
000000005028c730 000007feeaa9adad : 000000005028ccb8 000000005028ccb8 0000000000000001 000000005028cb50 : opencv_imgproc245!cvFindContours+0x3de [d:\downloads\opencv_2_4_5\opencv\modules\imgproc\src\contours.cpp @ 1688]
000000005028c8e0 000007fef1e1f89e : 000000000032aae2 0000000000000000 0000000000000000 0000000000000000 : opencv_imgproc245!cv::findContours+0x18d [d:\downloads\opencv_2_4_5\opencv\modules\imgproc\src\contours.cpp @ 1713]


Function where this is called from--edgeImage is always computed the same way for each image buffer we process and is of grayscale type. We zero it out first and then call Canny() with it passed in as a second parameter. I can share more of that code if necessary, but we do not see "edge image type to be passed..." in our logging.

void FindFeaturePoints(cv::Mat& edgeImage) const
{
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;

if (edgeImage.type() != CV_8U)
_logger->Fatal("Edge image type to be passed to findContours is NOT grayscale!");

findContours(edgeImage, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0) );
}


The line 1688 of contours.cpp is:

do
{
count++;
contour = cvFindNextContour( scanner );
}
while( contour != 0 ); //1688


(which WinDbg can be one line off on, and this means it's actually something in cvFindNextContour())

I'm just not sure why this would happen randomly--it seems to occur once every several million or so images we process. Again, we've been using the same bit of code around this and haven't seen the problem in months.

Any help is greatly appreciated, especially with taking the stack trace addresses and applying them to what might be going on in the actual findContours() function.