我刚开始使用Python和Numpy数组。我正在读取位于许多不同文件夹中的大量图像数据集。虽然读取图像时一切正常,但是我不断遇到错误,但我不确定到底是什么。我试图对此进行研究,但不幸的是我没有得到真正的答案。关于这个问题,请帮我。
我的代码如下。
import os
import numpy as np
import matplotlib.pyplot as mpplot
import matplotlib.image as mpimg
images = []
path = "../compCarsThesisData/"
for root, _, files in os.walk(path):
current_directory_path = os.path.abspath(root)
for f in files:
name, ext = os.path.splitext(f)
if ext == ".jpg":
current_image_path = os.path.join(current_directory_path, f)
current_image = mpimg.imread(current_image_path)
images.append(current_image)
print(files)
for img in images:
print (img.shape)
我面临的错误也在下面。
File "reading.py", line 15, in <module>
current_image = mpimg.imread(current_image_path)
File "C:\Users\zeele\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\image.py", line 1359, in imread with Image.open(fname) as image:
File "C:\Users\zeele\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 2618, in open
prefix = fp.read(16)
OSError: [Errno 22] Invalid argument
P.S。作为新成员,请不要介意问题不清楚或不直接。非常感谢您的帮助。 谢谢。