OpenCV Crashes with Stack Overflow Or Resorce Allocation Error

asked 2014-02-11 13:25:26 -0600

mfeinstein gravatar image

I have a multithread C++ Qt program using OpenCV 2.4.6 under VS2010 where one of the threads run an image processing algorithm.

I know my algorithm works because it runs fine in a console applicaiton, and I just copy and paste it in the project....then I get all this weird errors.

The code is:

//...some stuff

leftMat = imread("M:/Desktop/PsEyeRight1.jpg", CV_LOAD_IMAGE_COLOR); 
cvtColor(leftMat, leftMat, CV_RGB2GRAY);       
GaussianBlur(leftMat, leftMat, Size(3, 3), 0, 0, 4);                   
threshold(leftMat, leftMat, 150, 255, THRESH_BINARY); contoursLeft.clear();            
hierarchyLeft.clear();                        
Mat contourImage = leftMat.clone();           
findContours(contourImage, contoursLeft, hierarchyLeft, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0));

//...some stuff

When the execution hits findContours(), I get a StackOverflow as "Unhandled exception at 0x100a9985 (opencv_core246d.dll) in SARA.exe: 0xC00000FD: Stack overflow."

So I go to Configuration Properties > Linker > System > Stack Reserve Size and change it to "100000000" (100MB)

This time the error changes... cvtColor() crashes with the error "Unhandled exception at 0x774fc41f in SARA.exe: Microsoft C++ exception: Concurrency::scheduler_resource_allocation_error at memory location 0x1f63ad64.." at concrt.h and if I remove cvtColor(), Threshold() crashes the same way.

I am compiling it as /MDd (Multi-Threaded Debug DLL) and I have also tried to run CMake on OpenCV to clear the option "BUILD_WITH_STATIC_CRT", and I compiled openCV again, and the projects that I saw under the OpenCV solution, all had the /MDd as well as my program does.

Does anyone has a guess about what is going on?

EDIT: Just to make it clear, I have enough free memory in my system to run the program.

edit retag flag offensive close merge delete