本文根據實際情況做過修改
import os
import time
import cv2
def alter(path,out):
s = os.listdir(path)
for i in s:
document = os.path.join(path,i)
img = cv2.imread(document)
img = cv2.resize(img, (400,300))
fileName=i.split(".JPG")
cv2.imwrite(out+'%s.jpg' % fileName[0], img)
alter('e:\\orig','e:\\res\\')
源文件在e:\\orig,目標文件在e:\\res\\,轉換後的圖片大小爲 400x300