我正在尝试使用 PIL 来显示 JPEG 图像。我正在使用的代码是:
import numpy as np
from PIL import Image
for curr_im in f.readlines(): # Loop through file with names of image files
print(curr_im) #print name of image file
with Image.open(os.path.join('./sample/images/',curr_im)) as z:
z.show() # Show image
zz=np.asarray(z)
print(zz.max(), zz.min(), zz.dtype, zz.shape) # Verify something has been read
x=input("Pause")
我看到生成的输出是:
val_0.JPEG
255 0 uint8 (64, 64, 3)
Pause
val_1.JPEG
255 0 uint8 (64, 64, 3)
Pause
所以,我可以看到我正在读取存在的文件,并且正在读取非常像图像的东西。
但是打开显示图像的窗口是空白的,并且显示消息“在“file:///tmp/tmp.....PNG”中找不到图像。为什么会发生这种情况???(注意:“。 ...." 代替看似随机的字母和数字字符串。
我正在使用 Python 3.7.6 和 PIL 7.0.0。
注意:每隔一段时间,图像确实会正确显示,但我无法检测到押韵或原因。