C ++ OpenCV 2.4.0 findContours crashes with Kinect thread depth

Running problem with opencv 2.4.0 The findContours function is constantly crashing. Unfortunately, it was very difficult for me to identify the problem. Hope someone ran into a similar problem.

I collect a depth stream from a Kinect sensor using the Microsoft K4W SDK 1.5, copying it to Matrix OpenCV, and then converting it to an 8UC1 image via cvtColor and threshold. I run countNonZero to make sure the image is not empty before passing it to findContours. But even the simplest findcountours implementation crashes.

Here is my base code:

rawdepth = Mat(Size(640,480),CV_8UC4); thresh = Mat::zeros(640,480,CV_8UC1); // storage for contours vector<vector<Point>> contours; cvtColor(rawdepth,thresh,CV_RGB2GRAY); threshold(thresh,thresh,0,255,THRESH_BINARY); if(countNonZero(thresh) > 100 ) { // This crashes findContours(thresh,contours,RETR_EXTERNAL,CV_CHAIN_APPROX_NONE); } 

I made sure that the actual Mat passed to findcontours is a single-channel image and that it is not empty (i.e. there are more than 500 + points). But I am wondering if this is a heap or thread problem, since I heard that findcontours can really modify the input Mat file?

At this point, I will try to use OpenCV 2.4.1, which has just been released, although I do not see any fixed errors that indicate a fix for this problem.

Any ideas are greatly appreciated ...

+4
source share
3 answers

The problem turned out to be the compiler flag, which limited the use of the program stack to 10 MB (10,000,000 bytes). Unfortunately, this was not enough for the Kinect video I was shooting. After removing the compiler flag, findContours will now compile and work correctly!

I am using VC ++ 2010, and the compiler flags are in Project Properties β†’ Linker-> System. Two fields: "Stack reserve size" and "Stack lock size"

After cleaning and recompiling the project works beautifully!

+2
source

There are two possible problems here.

Firstly, the raw Kinect depth stream is 16 bits (the least significant 3 bits are the player’s index, the remaining 13 bits are the depth in mm), so if you copy this data into an 8-bit image, you get only half of it, and he is gobbledegook,

Secondly, OpenCV is compiled differently for debug and release configurations. If you are compiling a Debug profile, you need to use the debug libraries (version # d). So to use cv :: findContours you need opencv_imgproc240. [Lib / dll] and opencv_core240. [Lib / dll]. Neither cv :: namedWindow / cv :: imshow (which is very convenient for debugging) or cv :: findContours will work correctly if you use the wrong configuration.

Hope this helps.

+1
source

I wanted to notice that I had the same problem with the findContours () method crashing as mentioned in the second answer, the problem was that I was using a non-debug version of opencv_imgproc240.dll and opencv_core240.dll in debug mode, change to XXd.dll solved the problem.

+1
source

Source: https://habr.com/ru/post/1415833/


All Articles