1

I was doing line detection in OpenCV. Everything was going fine until i get this Debug assertion error:

Debug Assertion Failed! Expression: _pFirstBlock == pHead

Screenshot of the assertion

I spent days working on it but cannot debug it. This is my code.

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main() {
VideoCapture stream1(0);  
while (true) {
    Mat cameraFrame;
    stream1.read(cameraFrame);
    imshow("cam", cameraFrame);

    if (waitKey(30) >= 0)
        break;

    Mat src = cameraFrame;


    Mat dst, cdst;
    Canny(src, dst, 50, 200, 3);
    cvtColor(dst, cdst, CV_GRAY2BGR);

   vector<Vec4i> lines;

    HoughLinesP(dst, lines, 1, CV_PI / 180, 50, 50, 10);
    for (size_t i = 0; i < lines.size(); i++)
    {
    Vec4i l = lines[i];
    line(cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3, CV_AA);
    }

    imshow("processed", cdst);


}
return 0;
}
7
  • 1
    please paste the text of the exception, not a screenshot.. Commented Jul 22, 2014 at 7:54
  • also make sure, you don't mix debug/release libs Commented Jul 22, 2014 at 7:56
  • ERROR IS Debug assertion failed Program:...al studio 2013\Projects\Opencv2.4.9\x64\Debug\OpenCV2.4.9.exe File:f:\dd\vctools\crt\crtw32\misc\dbgheap.c Line:1424 Expression:_pFirstBlock==pHead For more onformation on how your program can cause assertion failure,see the visual C++ documentation on aserts. Commented Jul 22, 2014 at 8:09
  • 1
    nope i didnt mix the libraries code is working fine in release mode...but not in debug mode!! Commented Jul 22, 2014 at 8:18
  • If you click "Retry" to break at that assertion, you'll see it's trying to free some heap memory. Look at the call stack in the debugger and let us know which line in your source code is running. Commented Jul 22, 2014 at 9:20

2 Answers 2

2

This happens because OpenCV libraries are traditionally compiled with the following runtime library:

  • MD (Release)
  • MDd (Debug)

while my IDE Qt Creator, which uses MSVC 2013 with it's default configuration, builds stuff with:

  • MT (Release)
  • MTd (Debug)

Surprisingly, the error only manifested when HOG's compute() was invoked.

To fully understand the MT vs MD (runtime library) dilemma, read this.

There are 2 different ways to handle this issue. The easy way out is to adjust your projects setting to also use MD/MDd as runtime library and match OpenCV's!

On Qt Creator, this can be done in the .pro file by adding:

QMAKE_CXXFLAGS_DEBUG += /MDd
QMAKE_CXXFLAGS_RELEASE += /MD

On the other hand, on some versions of Visual Studio this can be done through your Project Properties >> Configuration Properties >> C/C++ >> Code Generation and changing the Runtime Library to:

  • Multi-threaded Debug DLL (/MDd), if you are building the Debug version of your code.
  • Multi-threaded DLL(/MD), if you are building the Release version of your code.

The other way to handle this issue is to rebuild/recompile OpenCV with BUILD_WITH_STATIC_CRT enabled. This will compile OpenCV libraries with MT/MTd support.

Sign up to request clarification or add additional context in comments.

Comments

-1

Maybe its the solution like the one, which helped for me.

You try using a Winforms with /clr specified for the GUI side calling into unmanaged code that at some point referenced a ATL header.

You need to bind the opencv Libarys in the linker dependencies ( opencv_calib2411d, ... care for Debug/Release and the opencv version you use)

additional:

add __DllMainCRTStartup@12 in Force Symbols Reference section in the Linker section of the project settings.

source https://social.msdn.microsoft.com/Forums/vstudio/en-US/62db4002-4ebc-4a3a-91ec-9fc702db821e/crtisvalidheappointerpuserdata-why-is-this-code-broken-vs2008?forum=vcgeneral

1 Comment

It's a totally different problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.