|
建議加入 try ~ except,如下: 1~11 略
myfiles = glob.glob("carNegative_sr/*.JPG") emptydir('carNegative') print('開始轉換尺寸及灰階!') for i, f in enumerate(myfiles): try: img = Image.open(f) img_new = img.resize((500, 375), PIL.Image.ANTIALIAS) img_new = img_new.convert('L') #轉換為灰階 outname = str("negGray") + str('{:0>3d}').format(i+1) + '.jpg' # img_new.save('carNegative/'+ outname) except: print("{}無法讀取..." .format(f))
print('轉換尺寸及灰階結束!') |