I am programming a DirectShow Filter that detects objects with an OpenCV HaarcascadeClassifier
. It is working fine in Debug mode but not in Release mode and I'm not sure whether there is an memory leak in the OpenCV function (VC 2010 binary of opencv_249 libs) or whether there is something wrong with my project (settings).
I am loading the filter in GraphStudio, a tool to build a DirectShow FilterGraph easily. I'm not sure whether there are assumptions about the filter DLL to be compiled in Debug mode or not.
I'm basically doing the following, after some preprocessing:
std::vector<cv::Rect> objects;
mClassifier.detectMultiScale(inputGray,objects, 1.3);
for(unsigned int i=0; i<objects.size(); ++i)
{
cv::rectangle(outputImage, objects[i], cv::Scalar(255,255,255));
}
So within the function block I am preprocessing, followed by the shown part of code and followed by writing the data to the DirectShow Buffer.
If I use the DLL in Release mode, I get the following error message AFTER the whole function terminated (so probably somewhere else inside the DirectShow Filtergraph):
Debug Assertion Failed!
Program: C:\Program Files (x86)\Graphstudio\graphstudio.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
Line: 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information [...]
followed by a
Debug Assertion Failed!
Program: C:\Program Files (x86)\Graphstudio\graphstudio.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
Line: 1322
Expression: _CrtlsValidHeapPointer(pUserData)
When I comment mClassifier.detectMultiScale(inputGray,objects, 1.3);
out, the filter doesn't crash. Though some things might be optimized away, I replaced the detectMultiScale
call with a loop that randomly (previously seeded with time(NULL)) inserts cv::Rect
objects into the vector. The filter does not crash and displays the random rectangles in the way I would assume.
I've read that others have observed (valgrind) cv::CascadeClassifiert::detectMultiScale
to produce memory leaks. And I've found a link where someone had a problem with detectSingleScale
and some OpenCV committer marked it to be fixed ( http://code.opencv.org/issues/2628 ).
Questions:
Is there a chance that this exact problem (see previous link) is (still) within detectMultiScale
?
Is there a chance that the problem is not within my project, but in the OpenCV library?
Why does this problem only occur in Release mode?
Why does this problem only occur in the DirectShow filter? (if I run the "same" code/functionality in Release mode in a stand-alone project, I don't get Debug Assert Failed
errors - though there might be a unrecognized memory corruption?!?).
I hope someone has an idea and thx in advance!
EDIT:
ok... I had linked against msvcrtd.lib
... removed the whole lib from my project (seems I didnt even need it) and it "works" now... There is the question left, whether there is some kind of memory leak. Or was linking against that lib the only whole problem?
ok... I had linked against msvcrtd.lib ...
removed the whole lib from my project (so default libs are added?!?) and it "works" now...
There is the question left, whether there is some kind of memory leak. Or was linking against that lib the only whole problem?
stupid me...