OpenCV中的调试声明错误 [英] Debug Assertion Error in OpenCV

查看:97
本文介绍了OpenCV中的调试声明错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenCV中进行线路检测.一切正常,直到出现此Debug断言错误:

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

调试断言失败!表达式:_pFirstBlock == pHead

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;
}

推荐答案

之所以会发生这种情况,是因为传统上OpenCV库是使用以下运行时库进行编译的:

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

  • MD (发布)
  • MDd (调试)
  • MD (Release)
  • MDd (Debug)

使用默认配置 MSVC 2013 的我的IDE Qt Creator 构建以下内容:

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

  • MT (发布)
  • MTd (调试)
  • MT (Release)
  • MTd (Debug)

令人惊讶的是,该错误仅在调用HOG的compute()时才出现.

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

要完全理解MT与MD(运行时库)的困境,请阅读此.

有2种不同的方法来处理此问题.简单的方法是调整项目设置,以同时将MD/MDd用作运行时库并与OpenCV匹配!

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!

在Qt Creator上,可以通过添加以下内容在.pro文件中完成

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

QMAKE_CXXFLAGS_DEBUG += /MDd
QMAKE_CXXFLAGS_RELEASE += /MD

另一方面,在某些版本的Visual Studio中,可以通过Project Properties >> Configuration Properties >> C/C++ >> Code Generation并将Runtime Library更改为:

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:

  • 多线程调试DLL(/MDd),如果您正在构建代码的 Debug 版本.
  • 多线程DLL(/MD),如果您正在构建代码的 Release 版本.
  • 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.

处理此问题的另一种方法是在启用BUILD_WITH_STATIC_CRT 的情况下重建/重新编译OpenCV.这将编译具有 MT/MTd 支持的OpenCV库.

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.

这篇关于OpenCV中的调试声明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆