Debug mode: Detector Mask works with ORB, crashes with Sift (bug) ? [closed]

asked 2013-06-11 06:27:30 -0600

yes123 gravatar image

updated 2013-06-11 11:25:57 -0600

I am using a simple code to extract keypoint outside a ROI. The code works with ORB but not with SIFT. Code:

vector<KeyPoint> kp;
Mat d;
string image = "image.png";

Mat M = imread(image,0);

//Ptr<FeatureDetector> det = new OrbFeatureDetector();   //> WORKS
Ptr<FeatureDetector> det = new SiftFeatureDetector();    //> CRASH at .detect

Rect roi(100,100,70,70);
Mat mask(M.size(), CV_8UC1, Scalar::all(255));
mask(roi).setTo(Scalar::all(0));

det->detect(M,kp,mask);

The detect method crashes with:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si
ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channel
s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3
) - 1))*4) & 15) == elemSize1()) in unknown function, file C:\slave\builds\WinIn
stallerMegaPack\src\opencv\modules\core\include\opencv2/core/mat.hpp, line 545

If i simply use ORB

Ptr<FeatureDetector> det = new OrbFeatureDetector();

with the same code the detect works just fine. (It works with Surf and Brisk detector too. It's just SIFT that crashes =/)

Note

If i use sift in Release mode the code doesnt' crash (because the ASSERT is never executed)

Note2

I have OpenCV 2.4.5 with Windows 8 64bit (and Visual studio 2012)

Full stack when crashes (only in debug mode using SIFT detector):

image description

testMask() line 303 is the call to ->detect

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-26 13:38:44.779895

Comments

@yes123: I can not replicate the error, can you please provide your image.png. Thank you. And are you sure it happens in that section of code?

Guanta gravatar imageGuanta ( 2013-06-11 07:31:26 -0600 )edit

@Guanta: I have only that in my main. Also it happens with every images. Also I have found that the error happens only in Debug mode. Not in realease mode! STRANGE. (or maybe not so strange because in release mode the CV_ASSERT is never executed)

yes123 gravatar imageyes123 ( 2013-06-11 07:41:48 -0600 )edit

@yes123 cannot reproduce it (using OpenCV 2.4.5 at Debian 64bit)

Guanta gravatar imageGuanta ( 2013-06-11 08:18:37 -0600 )edit

Can't reproduce it, either. What's your OpenCV version? Could you use the debugger to find the call to the method and, even better, look why the values are false? It seems that this happens in the at-method of the Mat object.

Notas gravatar imageNotas ( 2013-06-11 08:45:27 -0600 )edit

@Notas: I have added the full stack in my question. Also I have opencv2.4.5 (precompiled, so i can't digg inside features2d.dll) with windows 8 64bit and visual studio 2012. If i need to run other test please let me know

yes123 gravatar imageyes123 ( 2013-06-11 10:37:42 -0600 )edit

So line 303 is actually your detect-line? Or the line after that?

My advice is to compile OpenCV on your own, if you still have the problem, build OpenCV in debug-mode and see what causes the error. Maybe valgrind may also help you.

Guanta gravatar imageGuanta ( 2013-06-11 11:03:58 -0600 )edit

@Guanta: the call stack when the software crashes points to the line after the line that causes the crash. Anyway the line that crashes is ->detect (if you comment out all the following lines, the call stack points to the line of the ->detect). I will try to compile it on my own, but I think it's clear that the CV_ASSERT is wrong and should be either removed or fixed. At least is wrong in conjuction with SIFT

yes123 gravatar imageyes123 ( 2013-06-11 11:24:59 -0600 )edit
1

Hmm, at least sth is not working properly. When you build OpenCV on your own, you can also split the long assertion in small parts (so each part starting w. && in an own CV_Assert) - really a bad practice to write such long asserts...

Guanta gravatar imageGuanta ( 2013-06-11 14:45:18 -0600 )edit

Totally agree with you. Also those assert are pretty hard to read and correctly understand which is the problem. Maybe I can try (before the ->detect call) to simulate those assert manually to understand which is the problem ? Having defined both Image KPs and Mask ? But sincerly I don't know how to translate the last condition especially... (sizeof(size_t)) < 28 ...

yes123 gravatar imageyes123 ( 2013-06-11 14:53:04 -0600 )edit

me neither ;)

Guanta gravatar imageGuanta ( 2013-06-11 15:15:26 -0600 )edit