簡體   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