输入主文件夹目录:D:\flower\flower_photos
下面有多个子文件夹
import os
import glob
import cv2
import numpy as np
data_dir = 'D:/flower/flower_photos'#输入主文件夹路径
file = 'D:/flower/padding'#输出路径
for parent1, dirnames1, filenames1 in os.walk(data_dir):
for dirname1 in dirnames1:
rootdir = parent1 + '/' + dirname1
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
img = os.path.join(parent + '/' + filename)
img = cv2.imread(img)
size = img.shape
h, w = size[0], size[1]
m = max(w, h)
resize_img = cv2.resize(img, (w, h))
if m == w: