OpenCV Python不使用imread()打开图像 [英] OpenCV Python not opening images with imread()

查看:626
本文介绍了OpenCV Python不使用imread()打开图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么会发生这种情况,但是我正在编写一个程序,并且遇到了很多问题,试图使opencv使用imread打开图像.我不断收到错误消息,指出图片的宽度为0px,高度为0px.这对我来说没有多大意义,所以我在这里四处搜寻,我也没有得到任何答案.

I'm not entirely sure why this is happening but I am in the process of making a program and I am having tons of issues trying to get opencv to open images using imread. I keep getting errors saying that the image is 0px wide by 0px high. This isn't making much sense to me so I searched around on here and I'm not getting any answers from SO either.

我已经拍摄了约20张照片,而且它们都使用同一设备.其中可能有8个实际上可以正常打开并正常工作,而其余的则不能.它们也没有损坏,因为它们是在其他程序中打开的.我对路径进行了三重检查,它们正在使用完整路径.

I have taken about 20 pictures and they are all using the same device. Probably 8 of them actually open and work correctly, the rest don't. They aren't corrupted either because they open in other programs. I have triple checked the paths and they are using full paths.

还有其他人遇到这样的问题吗?我所有的文件都是.jpgs,但我看不到任何问题.这是一个错误还是我做错了什么?

Is anyone else having issues like this? All of my files are .jpgs and I am not seeing any problems on my end. Is this a bug or am I doing something wrong?

这是我正在使用的代码的片段,正在再现我的错误.

Here is a snippet of the code that I am using that is reproducing the error on my end.

imgloc = "F:\Kyle\Desktop\Coinjar\Test images\ten.png"
img = cv2.imread(imgloc)
cv2.imshow('img',img)

当我更改文件时,我只是调整了文件本身的名称,整个路径并没有改变,只是拒绝接受我的某些图像,这些图像本质上是相同的.

When I change the file I just adjust the name of the file itself the entire path doesn't change it just refuses to accept some of my images which are essentially the same ones.

我从稍后尝试使用img.shape的代码中收到此错误

I am getting this error from a later part of the code where I try to use img.shape

Traceback (most recent call last):
  File "F:\Kyle\Desktop\Coinjar\CoinJar Test2.py", line 14, in <module>
    height, width, depth = img.shape
AttributeError: 'NoneType' object has no attribute 'shape'

当我尝试从上面的代码片段显示一个窗口时,我得到了这个错误.

and I am getting this error when I try to show a window from the code snippet above.

Traceback (most recent call last):
  File "F:\Kyle\Desktop\Coinjar\CoinJar Test2.py", line 11, in <module>
    cv2.imshow('img',img)
error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow

推荐答案

可能是文本中\的特殊含义有问题-如\t\n

Probably you have problem with special meaning of \ in text - like \t or \n

使用\\代替\

imgloc = "F:\\Kyle\\Desktop\\Coinjar\\Test images\\ten.png"

r''

imgloc = r"F:\Kyle\Desktop\Coinjar\Test images\ten.png"


除了/以外的某些模块-例如在Linux路径中

Some modules except even / - like in Linux path

imgloc = "F:/Kyle/Desktop/Coinjar/Test images/ten.png"

这篇关于OpenCV Python不使用imread()打开图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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