无法在opencv中读取图像 [英] Can not read image in opencv

查看:193
本文介绍了无法在opencv中读取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的opencv,我开始做一个简单的代码读取和显示图像在gui,我在qt IDE工作,首先我wirte这块代码

I am new to opencv and I am starting to make a simple code to read and display image in gui ,I am working in qt IDE, first I wirte this block of code

#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
然后,我写了另一个有效性代码来检查图片是否已被读取。

But it displays a white window and error in console and then display another window "not responsive" message and then stop working, This is a screen shot http://pbrd.co/1u2A0ow Then I wrote another validity code to check wheater or not the image is been read

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

It displays the message, which means that the image is not read,So The question is How can I successfully read and load image note: The image in the same folder of main.cpp file http://pbrd.co/1u2Bmj1

推荐答案

正如你所说下面的代码显示你的文件不存在:

As you said following code showed you that file not exist:

QFile file("image.jpg");
     if(file.exists())
         cout<<"\n exist \n"<<endl;
     else
         cout<<"\n not exist \n"<<endl;

解决方案:

尝试设置您的图像的完整路径。由于某些原因,Qt在错误的地方搜索您的文件,因此设置完整路径。

First of all, try to set full path to your image. For some reasons Qt search your file in wrong place, so set full path.

例如:

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;

这篇关于无法在opencv中读取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆