findContours Exception [closed]

asked 2015-10-30 18:06:32 -0500

RPH gravatar image

updated 2015-10-30 19:19:50 -0500

Hi, I just have simple code to find the contours in an image :

vector <vector<Point2i>>cont;
frame = imread("hw.jpg");
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
background = imread("background.jpg");
//convert background to grayscale
cvtColor(background, background_gray, COLOR_BGR2GRAY);
//perform frame differencing
absdiff(background_gray, frame_gray, DifferenceImage);
//obtain threshold image
threshold(DifferenceImage, ThresholdImage, 45, 255, THRESH_BINARY);
//blur image
blur(ThresholdImage, BlurImage, Size(40, 40));
threshold(BlurImage, ThresholdImage2, 45, 255, THRESH_BINARY);
findContours(ThresholdImage2, cont, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
imshow("Capture", frame);
imshow("Threshold Image", ThresholdImage2);

I get the exception "Unhandled exception at 0x6F04C3A2 (ucrtbase.dll). An invalid parameter was passed to a function that considers invalid parameters fatal." What's wrong ? Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-10 14:35:10.328863


What function thows that exception? can you provide the original image ("hw.jpg") to test the code? Also, please post OS and OpenCV version

LorenaGdL gravatar imageLorenaGdL ( 2015-10-30 18:09:16 -0500 )edit

@LorenaGdL OpenCV version 2.4.11, Windows 10. If I comment out the findContours function then there's no exception.

The exception is thrown after the program finishes running though....

RPH gravatar imageRPH ( 2015-10-30 18:26:01 -0500 )edit

@RPH, Try to use "ThresholdImage2.clone()" in findContours

aydin_1918 gravatar imageaydin_1918 ( 2015-10-31 02:32:16 -0500 )edit

Please, provide the background image too.

LorenaGdL gravatar imageLorenaGdL ( 2015-10-31 04:46:28 -0500 )edit

@aydin_1918 I still get the same exception.

@LorenaGdL My apologies, here's the background:

RPH gravatar imageRPH ( 2015-10-31 06:25:18 -0500 )edit

I can't reproduce the issue with OpenCV 2.4.12 in Win7 x64. I remember someone asking not long ago about the same exception, but I can't remember in what thread (you might try to find such thread...). About using "ThresholdImage2.clone()" in findContours(), it won't solve your issue but it will allow to show the correct binary image in your imshow (finContours() "eats" and changes your input image)

LorenaGdL gravatar imageLorenaGdL ( 2015-10-31 06:57:33 -0500 )edit

Searching around internet I've found that ucrtbase.dll is a brand new dll for Windows 10, so it seems like an incompatibility issue of some kind. Not very sure there's anything you can do about it...

LorenaGdL gravatar imageLorenaGdL ( 2015-10-31 07:12:32 -0500 )edit

Oh no...I did some searching but I didn't find many other threads with the same issue...I'm not sure what to do then...I'm using Visual Studio 2015, I think that may be the problem..

RPH gravatar imageRPH ( 2015-10-31 07:48:50 -0500 )edit

@LorenaGdL I tried rebuilding the opencv library for VS 2015 but I can't get the opencv solution to compile as it gives build errors. I may just have to revert to using VS 2013....

RPH gravatar imageRPH ( 2015-10-31 12:23:24 -0500 )edit

@RPH it works with VS 2015

LBerger gravatar imageLBerger ( 2015-11-01 05:17:59 -0500 )edit