import os
import cv2
path = r' ..... ' # 图像所在路径
filelist = os.listdir(path)
print(len(filelist))
for file in filelist:
orgin_dir = os.path.join(path, file) # 原路径
print(orgin_dir) # 检查路径
img = cv2.imread(orgin_dir, cv2.IMREAD_GRAYSCALE) # 读取灰度图
print(img.shape) # 打印维度
cv2.imwrite(orgin_dir, img) # 覆盖原图