无法读取opencv中的图像
Can not read image in opencv
我是opencv的新手,我开始制作一个简单的代码来读取和显示gui中的图像,我在qt IDE中工作,首先我编写了这段代码
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
int main()
{
cv::Mat image=cv::imread("image.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image",image);
cv::waitKey(0);
cv::destroyAllWindows();
return 1;
}
但它在控制台中显示一个白色窗口和错误,然后显示另一个窗口"未响应"消息,然后停止工作,这是屏幕截图http://pbrd.co/1u2A0ow然后我写了另一个有效代码来检查图像是否已读取
int main()
{
Mat image;
cout<<"Size is"<<image.size().height<<","<<image.size().width<<endl;
image=imread("image.jpg");
//Checking first if the image have been read
if(!image.data)
{
cout<<"n No image has created n"<<endl;
}
return 1;
}
它显示消息,这意味着图像没有被读取,所以问题是如何成功读取和加载图像注意:main.cpp文件的同一文件夹中的图像http://pbrd.co/1u2Bmj1
正如您所说,以下代码显示该文件不存在:
QFile file("image.jpg");
if(file.exists())
cout<<"n exist n"<<endl;
else
cout<<"n not exist n"<<endl;
解决方案:
首先,试着设置你的图像的完整路径。由于某些原因,Qt在错误的位置搜索您的文件,所以设置完整路径。
例如:
cv::Mat image=cv::imread("G:\2\qt.jpg");
QFile file("G:\2\qt.jpg");
if(file.exists())
cout<<"n exist n"<<endl;
else
cout<<"n not exist n"<<endl;
或者UNIX风格:
cv::Mat image=cv::imread("G:/2/qt.jpg");
QFile file("G:/2/qt.jpg");
if(file.exists())
qDebug()<<"n exist n"<<endl;
else
qDebug()<<"n not exist n"<<endl;
程序似乎不知道映像在哪里。请尝试将main.cpp作为程序将使用的库之一。这样,程序将能够找到并打开图像。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- 如果不在窗口 10 中声明名为 openCV 的 openCV namedWindow,QT 图像显示将无法正常工作
- 在本地网络中通过OpenCV(C++)实时流式传输图像
- 如何在 OpenCV 中将图像与另一个图像相关联
- 如何在 OpenCV c++ 中压缩 TIFF 格式的图像?
- OpenCV - 如何在灰度图像上应用 Kmeans?
- 阅读和处理图像(OpenCV/C )
- cv::findContours 正在修改源图像 OpenCV 2.3
- 将图像替换为更大尺寸的图像 (OpenCV)
- 显示像素值已更改的图像openCV
- 具有积分图像的快速模糊图像(OpenCV)
- 扫描图像OpenCV上的文档检测
- 使用cv::Mat图像(opencv)如何检测对象
- 写作和展示图像OpenCV
- 从文件夹中读取图像(OpenCV)
- 无法保存从网络摄像头捕获的图像(OpenCV 2.3 的 imwrite 编译错误)
- 旋转不变的多个模板出现在图像Opencv