Python 3.x 为什么PIL不能显示有错误的图像;在“中找不到图像”;file:///tmp/tmp.....PNG"

Python 3.x 为什么PIL不能显示有错误的图像;在“中找不到图像”;file:///tmp/tmp.....PNG",python-3.x,python-imaging-library,Python 3.x,Python Imaging Library,我正在尝试使用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('./s

我正在尝试使用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


注意:每隔一段时间,图像确实会正确显示,但我无法检测到任何押韵或原因。

单个图像是否正确显示?例如使用
image.open('./sample/images/val_0.JPEG').show()
?如果它不起作用,您是否尝试过其他模块,例如skimage:
skimage.io.imshow('.');plt.show()
单个图像是否正确显示?例如使用
image.open('./sample/images/val_0.JPEG').show()
?如果它不起作用,您是否尝试过其他模块,例如skimage:
skimage.io.imshow('.');plt.show()