繁体   English   中英

尝试运行OpenCV程序时,Qt Creator崩溃。 [ntdll.dll崩溃]

[英]Qt Creator crashes when trying to run an OpenCV program. [ntdll.dll crash]

我有用于Windows的QT Creator 3.2.2。 我正在使用mingw-x64和gcc / g ++-4.9.1作为我的编译器/调试器。 我使用Cmake构建库。

目前,我正在尝试运行以下代码:

#include <core/cvstd.hpp>
#include <core/mat.hpp>
#include <core/types.hpp>
#include <core.hpp>
#include <cstdlib>
#include <highgui.hpp>
#include <imgproc.hpp>
#include <iostream>
#include <sys/types.h>
#include <vector>
#include <video/background_segm.hpp>

using namespace cv;

int main(int argc, char *argv[])
{
  Mat image = imread("C:\\Users\\John\\Desktop\\Random\\QtTrySimple\\Try\\bgm.jpeg");
  namedWindow("LOL");
  imshow("LOL", image);    
}

但是程序崩溃并显示“检测到严重错误c0000374”。 据我了解,此错误表示堆上发生内存泄漏。

另外,这是崩溃时的堆栈:

0   ntdll!RtlUnhandledExceptionFilter   C:\Windows\SYSTEM32\ntdll.dll       0x775b40d0  
1   ntdll!EtwEnumerateProcessRegGuids   C:\Windows\SYSTEM32\ntdll.dll       0x775b4746  
2   ntdll!RtlQueryProcessLockInformation    C:\Windows\SYSTEM32\ntdll.dll       0x775b5952  
3   ntdll!RtlLogStackBackTrace  C:\Windows\SYSTEM32\ntdll.dll       0x775b7604  
4   ntdll!RtlIsDosDeviceName_U  C:\Windows\SYSTEM32\ntdll.dll       0x7755dc47  

我不知道为什么发生内存泄漏。 但是我猜想这与使用Windows API来显示显示窗口的OpenCV有关。

编辑:图像不为空。 我正在检查代码中是否有空图像。

由于缺乏信息,我只能猜测这是cv::imread()返回空cv::Mat的明显情况。 当无法找到/打开文件时,会发生这种情况:

Mat image = imread("C:\\Users\\John\\Desktop\\Random\\QtTrySimple\\Try\\bgm.jpeg");
if (image.empty())
{
    std::cout << "!!! Failed to open image" << std::endl;
    return -1;      
}

imshow("LOL", image);    
waitKey(0);

在这种情况下,发生崩溃是因为调用了imshow()来显示...什么都没有。

不要忘了最后调用waitKey(0) ,否则窗口将立即关闭,您将无法看到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM