无法在 Opencv 中显示图像导致内存位置

Can't display image in Opencv cause memory location

本文关键字:图像 内存 位置 显示图 显示 Opencv      更新时间:2023-10-16

我试图用opencv显示图像,但失败了。搜索谷歌,不知道最近的一个如何仅显示调试

这里的代码

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("dom.png");
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);// It stuck here
waitKey(0);
return 0;
}

我尝试将img放入资源文件和源文件中,但仍然出错。该平台适用于 x64 .

Exception thrown at 0x00007FFBE404A388 in Opencv_01.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000768258F1B0.
Unhandled exception at 0x00007FFBE404A388 in Opencv_01.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000768258F1B0.

我哪里做错了?

问题是您没有处理 if 无法加载图像的情况。也许在程序的 currnet 目录中找不到它。

检查图像是否已加载的方法如下:

int main()
{
Mat img = imread("dom.png");
if(!img.data) {
cout << "Could not load image" << 'n';
return 1;
}
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);// It stuck here
waitKey(0);
return 0;
}