Reputation: 76
I was doing line detection in OpenCV. Everything was going fine until i get this Debug assertion error:
Debug Assertion Failed! Expression: _pFirstBlock == pHead
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;
}
Upvotes: 1
Views: 2248
Reputation: 93410
This happens because OpenCV libraries are traditionally compiled with the following runtime library:
while my IDE Qt Creator, which uses MSVC 2013 with it's default configuration, builds stuff with:
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:
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.
Upvotes: 2
Reputation: 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.
Upvotes: -1