Debug mode: Detector Mask works with ORB, crashes with Sift (bug) ? [closed]
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):
testMask() line 303 is the call to ->detect
@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: 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 cannot reproduce it (using OpenCV 2.4.5 at Debian 64bit)
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: 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
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: 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
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...
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 ...
me neither ;)