Python实现文件夹下图片顺序读取
文件结构如下:
看起来顺序的,但是读取出来并不是
可以采用sort()函数
import os
datasets_path = 'D:/Porousmedium/dataset/testset/test' # 数据集路径
images_path = os.path.join(datasets_path)
images_name = os.listdir(images_path)
images_name.sort(key=lambda x: int(x.replace("image_","").split('.')[0]))
for photo_name in images_name:
print(photo_name)