PIL庫進行圖片的resize
from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=768,height=384):
img=Image.open(jpgfile)
new_img=img.resize((width,height),Image.BILINEAR)
new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
for jpgfile in glob.glob("./training/image_2/*.png"):
convertjpg(jpgfile,"./training_resize/image_2/")
github連接如下: