我有QT Creator 3.2.2 for windows。我使用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);
}
但是程序崩溃,并显示“Critical error detected 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
我不知道为什么会发生内存泄漏。但我猜这与OpenCV使用windows API来显示窗口有关。
编辑:图像不是空的。我正在检查代码中是否有空图像。
发布于 2014-11-17 07:35:43
由于缺乏信息,我只能猜测这是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)
,否则窗口将立即关闭,您将无法看到它。
https://stackoverflow.com/questions/26963351
复制相似问题