无法查看jpeg文件

问题描述 投票:0回答:1

我试图使用我在网上找到的代码查看jpeg文件。

这里是代码:

from PIL import Image
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

image = Image.open('/kaggle/input/chest-xray-pneumonia/chest_xray/__MACOSX/chest_xray/test/PNEUMONIA/._person121_bacteria_576.jpeg')
image.show()

但我收到此错误:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-637f422434fd> in <module>
     19 
     20 
---> 21 image = Image.open('/kaggle/input/chest-xray-pneumonia/chest_xray/__MACOSX/chest_xray/test/PNEUMONIA/._person121_bacteria_576.jpeg')
     22 image.show()

/opt/conda/lib/python3.6/site-packages/PIL/Image.py in open(fp, mode)
   2685         warnings.warn(message)
   2686     raise IOError("cannot identify image file %r"
-> 2687                   % (filename if filename else fp))
   2688 
   2689 #

OSError: cannot identify image file '/kaggle/input/chest-xray-pneumonia/chest_xray/__MACOSX/chest_xray/test/PNEUMONIA/._person121_bacteria_576.jpeg'

我想知道这是否是一个问题,因为我没有加载数据或其他东西?我在Kagglenotebook上的笔记本上没有写其他数据集:https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia

python jpeg kaggle
1个回答
0
投票

我不确定这是否可以解决您的问题,但是通常在使用PIL模块时将文件命名为.jpg,然后引用文件路径。

我用重命名的image.jpg文件尝试了您的代码,当我使用'.jpeg'时,它工作正常,出现类似的错误。

from PIL import Image
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

image = Image.open('/Users/GameComputerC/ocr3.jpg')
image.show()

让我知道它是否对您有用。那可能只是错误的一部分。

© www.soinside.com 2019 - 2024. All rights reserved.