import os
# specify the img directory path
path = "path/to/img/folder/"
# list files in img directory
files = os.listdir(path)
for file in files:
# make sure file is an image
if file.endswith(('.jpg', '.png', 'jpeg')):
img_path = path + file
# load file as image...
import glob
for filename in glob.iglob(root_dir + '**/*.jpg', recursive=True):
# Do something
import cv2
import glob
imdir = 'path/to/files/'
ext = ['png', 'jpg', 'gif'] # Add image formats here
files = []
[files.extend(glob.glob(imdir + '*.' + e)) for e in ext]
images = [cv2.imread(file) for file in files]