繁体   English   中英

Python Mac Matplotlib读取错误

[英]Python mac matplotlib imread error

我正在尝试使用matplotlib的pyplot读取jpg图像。

这是使用imread命令时遇到的错误:

Traceback (most recent call last):
File "/Users/rugheid/Dropbox/Documents/Rugen Dropbox/School/Universiteit/3e jaar/P&O/Git Repository/backend/image_processing/image_processor.py", line 27, in <module>
img = pyplot.imread(io.BytesIO(jpg_bytes), format='jpg')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 2177, in imread
return _imread(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1242, in imread
im = pilread(fname)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1226, in pilread
return pil_to_array(image)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1328, in pil_to_array
x = toarray(im)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/image.py", line 1313, in toarray
x_str = im.tostring('raw', im.mode)
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 695, in tostring
"Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.

看来它正在从PIL中调用某些已删除的内容...我可以将matplotlib更改为使用Pillow而不是PIL吗? 还是我可以做点别的? 我安装了最新版本的matplotlib。

提前致谢!

您可能应该直接使用pillow ,因为对于除PNG文件以外的任何内容, matplotlib退回到PIL 文档中

matplotlib只能本地读取PNG,但是如果安装了PIL,它将使用它来加载图像并返回一个数组(如果可能)

要用pillow加载JPG:

from PIL import Image
im = Image.open('myimage.jpg')

这样,您可以裁剪中间人并直接控制图像加载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM