我正在尝试使用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改为使用枕头而不是PIL吗?或者我能做点别的吗?我已经安装了最新版本的matplotlib。
提前感谢!
发布于 2016-02-11 13:37:22
您可能应该直接使用pillow,因为matplotlib只是返回到PIL,而不是PNG文件。来自文献资料
matplotlib只能本地读取PNG,但是如果安装了PIL,它将使用它加载映像并返回数组(如果可能的话)。
用pillow加载JPG
from PIL import Image
im = Image.open('myimage.jpg')这样你就可以切掉中间的人,直接控制图像的加载。
https://stackoverflow.com/questions/35336757
复制相似问题