Ask Your Question

mfeinstein's profile - activity

2014-02-24 16:04:19 -0600 asked a question C++ Compilation introduce errors

I have a multi-threaded C++ windows project in Visual Studio 2010 which uses Qt (5.1.1) and OpenCV (2.4.8). When I build it in Debug mode everything runs fine, but when I build it in Release mode the program crashes. Both configurations are almost identical (just in Release I have Multi-threaded DLL /MD and in Debug Multi-threaded Debug DLL /MDd), I disabled optimizations for the Release, and even enabled debug to catch the error. What's most weird is that the same piece of code that crashes, runs just fine in another console project.

The error is internal to OpenCV's code, it's not related to my code, my code is just:

void MyProject::findEllipses(QImage &frame, vector<RotatedRect> &ellipses)
{      
    Mat image = Mat(frame.height(), frame.width(), CV_8UC4, frame.scanLine(0));                 

    cvtColor(image, image, CV_RGB2GRAY);
    GaussianBlur(image, image, Size(3, 3), 0, 0, 4);            
    threshold(image, image, treshVal, 255, THRESH_BINARY);

    vector<vector<Point> > contours;               
    Mat contoursImage = image.clone();    
    findContours(contoursImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0)); 
    // ....Mode Code

As I said in Debug the code runs without a problem, findContours() calls _contours.create(total, 1, 0, -1, true); (in line 1720 of OpenCV's contours.cpp) and moves on that method....BUT in Release, when I step into _contours.create(), instead of executing that method, the program jumps to void _OutputArray::clear() const (line 1674 of matrix.cpp) and get's trapped in there, because it calls int k = kind(); in it's first line, which, instead of calling cv::kind(), calls:

 int _InputArray::type(int i) const
 {
    int k = kind();

Which calls againg kind() which again calls type() (instead of kind() as it should), making an infinite recursive loop, bringing a stack overflow.

I tried to make a new Visual Studio 2010 project to see if this is a project creation problem but the problem persisted.

My guess is that the function adresses are wrong in release mode so when it tries to call create(), it instead calls another address, making a mess in the stack, but that's just my guess. At first I will blame OpenCV release dlls, but, as I said, in another console project that only runs that particular code, the code runs fine in bot build modes. I don't see how my other threads and code can trigger this behavior, since the error goes down to a wrong function call in OpenCV.

This is way beyond my knowledge and I have no idea how to fix this, I appreciate all the help I can get on this problem, because I already exausted all my ideas to fix it....

EDIT :

I made a small project so anyone can see what's happening.

The files are in: https://app.box.com/s/3owljl44emv57erinrf8

In order to run it, you have to have OpenCV 2.4.8 and Qt 5.1.1 and configure the Visual Studio 2010 project to get the include files from the right places. In the resources folder ... (more)

2014-02-18 21:25:38 -0600 commented answer ellipse() bug found!

Thanks, now there is just a weird behaviour I get in findContours() when I compile it as release...it does a stackoverlow....I cant debug it since it's release, but removing findContours() makes the program run nicely...maybe its a bug in the dll? I wish I could foward this to someone more expert than me to analise it further....but I dont know anyone :/

2014-02-18 08:15:01 -0600 received badge  Teacher (source)
2014-02-18 02:01:15 -0600 received badge  Self-Learner (source)
2014-02-18 01:42:15 -0600 commented answer ellipse() bug found!

Well I cant accept my own answer, so if someone places one like this I will accept

2014-02-18 01:41:20 -0600 answered a question ellipse() bug found!

It was already fixed in the new version, sorry for this.

2014-02-18 01:32:26 -0600 commented question ellipse() bug found!

I know, I just cant do it right now...can you check this for me?

2014-02-13 02:04:55 -0600 received badge  Editor (source)
2014-02-13 02:03:35 -0600 asked a question ellipse() bug found!

I am using OpenCV 2.4.6, I cant test it in the most recent versions, so I thougt it will be just better to place it in here...I am sorry if this was already corrected in the most recent ones.

If I call ellipse() as:

ellipse(image, RotatedRect(Point2f(-78877.320,-79104.328),Size2f(1.0649987e-010f,3.1949962e-010f),0.0f), CV_RGB(255, 0, 0), 1, 8); // OpenCV Bug discovered!

being image a 640x480 image, my program crashes.

ellipse() calls EllipeseEx() who calls ellipse2Poly() who crashes.

ellipse() does:

Point center(cvRound(box.center.x*(1 << XY_SHIFT)), cvRound(box.center.y*(1 << XY_SHIFT)));

which makes center.x and center.y equals to INT_MIN. this way ellipse2Poly() crashes when it tries in it's last line to acessa an empty vector [0] position in:

if( pts.size() < 2 )
        pts.push_back(pts[0]);

since for this case

if( pt != prevPt )
            pts.push_back(pt);

Is never != so the push_back() is never executed.

The code should be changed to

if( pts.size() < 2  && pts.size() > 0 )
        pts.push_back(pts[0]);

So this way, the vector will be never acessed in case it's empty, crashing the program.

I am sorry to not submit this to the repository myself, I just can't upload that code right now.

2014-02-11 13:25:26 -0600 asked a question OpenCV Crashes with Stack Overflow Or Resorce Allocation Error

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.