简体   繁体   English

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

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

I have QT Creator 3.2.2 for windows. 我有用于Windows的QT Creator 3.2.2。 I am using mingw-x64 with gcc/g++ - 4.9.1 as my compiler/debugger. 我正在使用mingw-x64和gcc / g ++-4.9.1作为我的编译器/调试器。 I used Cmake to build the libraries. 我使用Cmake构建库。

Currently, am trying to run this code : 目前,我正在尝试运行以下代码:

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

But the program crashes with a 'Critical error detected c0000374'. 但是程序崩溃并显示“检测到严重错误c0000374”。 From what I understand this error indicates a memory leak on the heap. 据我了解,此错误表示堆上发生内存泄漏。

Also, here is the stack when it crashes: 另外,这是崩溃时的堆栈:

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  

I have no idea why the memory leak is happening. 我不知道为什么发生内存泄漏。 But am guessing it's something to do with OpenCV using windows API to show a display window. 但是我猜想这与使用Windows API来显示显示窗口的OpenCV有关。

EDIT : The image isn't empty. 编辑:图像不为空。 I am checking for an empty image in my code. 我正在检查代码中是否有空图像。

Due to the lack of information, I can only guess this is the obvious case of cv::imread() returning an empty cv::Mat . 由于缺乏信息,我只能猜测这是cv::imread()返回空cv::Mat的明显情况。 This happens when it fails to find/open the file: 当无法找到/打开文件时,会发生这种情况:

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

In this case, the crash happens because imshow() is invoked to display... nothing. 在这种情况下,发生崩溃是因为调用了imshow()来显示...什么都没有。

Don't forget to call waitKey(0) at the end, or the window will be closed immediately and you won't be able to see it. 不要忘了最后调用waitKey(0) ,否则窗口将立即关闭,您将无法看到它。

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

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