我正在尝试使用PIL库处理一组图像。导入图像没有问题,但是当我试图从列表中访问第一个图像的大小信息时,我收到了一个错误。功能:
def loadImages(path):
image_path = listdir(path)
image_list = []
for img in image_path:
image = Image.open(path + img)
image_list.append(image)
return image_list
path = 'path/to/images'
images = loadImages(path)
N = len(images)
print("Number of images:", N)
w,h= Image.open(images[0]).size
以及整个错误列表:
^{pr2}$我正在研究: 枕头5.0.0 python 3.6.4
看起来你要打开图像两次。在
loadImage
中一次,然后在以后尝试打开Image.open
返回的内容(已经是图像):因为
^{pr2}$images[0] = Image.open(path + listdir(path)[0])
,您可以有效地使用上面的行执行以下操作:你应该能够做到:
相关问题 更多 >
编程相关推荐