Python 如何将所有图像数据转换为数组

Python 如何将所有图像数据转换为数组,python,Python,您可以使用os模块列出目录中的所有文件: folder = r'C:\Users\jabed\Desktop\mask and not mask\train\with mask' onlyfiles = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))] print("Working with {0} images".format(len(onlyfiles))) 您收到的

您可以使用
os
模块列出目录中的所有文件:

folder = r'C:\Users\jabed\Desktop\mask and not mask\train\with mask'

onlyfiles = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]

print("Working with {0} images".format(len(onlyfiles)))

您收到的错误是什么?查看问题我想将所有目录图像转换为数组..您可以循环浏览所有文件,检查它们是否包含图像文件扩展名,如
.png
.jpg
,等等。
import os

path = "C:\\someLocation"
onlyfiles = os.listdir(path)