试图运行简单的PIL python示例,无法将jpeg转换为float [英] Trying to run simple PIL python example, can't convert jpeg to float
本文介绍了试图运行简单的PIL python示例,无法将jpeg转换为float的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我写了一个简单的python脚本
so I wrote a simple python script
from PIL import Image
from pylab import *
im = array(Image.open('sample.jpg'))
imshow(im)
我从IDLE得到这个错误
and i get this error from IDLE
Traceback (most recent call last):
File "/home/michael/Dropbox/OpenCV/greyscale.py", line 5, in <module>
imshow(im)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 2722, in imshow
imlim=imlim, resample=resample, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes.py", line 7091, in imshow
im.set_data(X)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 418, in set_data
raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float
基本上我说我可以没有隐瞒我的形象漂浮,任何人都知道我失踪了什么
basically says i can not covert my image to float, anyone know what im missing
推荐答案
我知道这会很晚才到,但我想我应该回答以防万一其他人有同样的问题。我遇到了同样的问题,问题是我加载的图像在项目文件夹中不存在。所以你需要检查 sample.jpg
是否存在并且它正确加载在使用之前。
I know this is coming very later but I thought I should answer just in case anyone else had the same problem. I ran into the same problem and the issue was the image I loaded did not exist in the project folder.so you need to check that sample.jpg
exist and that it loads properly before using it.
if os.path.isfile('sample.jpg'): im = array(Image.open('sample.jpg'))
if im == None or im.size == 0:
print 'Image loaded is empty'
sys.exit(1)
这篇关于试图运行简单的PIL python示例,无法将jpeg转换为float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文