glob 文件名模式匹配,不用遍历整个目录判断每个文件是不是符合。
import glob
import cv2
car_images = glob.glob('OriginalDataset/vehicles/**/*.png', recursive=True)
notcar_images = glob.glob('OriginalDataset/non-vehicles/**/*.png', recursive=True)
for car in car_images:
cars.append(cv2.imread(car))
for ncar in notcar_images:
notcars.append(cv2.imread(ncar))