简体   繁体   中英

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

I have QT Creator 3.2.2 for windows. I am using mingw-x64 with gcc/g++ - 4.9.1 as my compiler/debugger. I used Cmake to build the libraries.

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'. 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.

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 . 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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