from PIL import Image
import os.path
def convertSize(files_dir,width=1024,height=299): #图片的大小
file_dir = os.listdir(files_dir)
for file in file_dir:
file_path = os.path.join(files_dir,file)
img = Image.open(file_path)
img = img.resize((1024, 299))
img = img.save(file_path)
convertSize('D:\毕设\ACE中文手写字识别\HWDB2.2Train_images')
file_dir = os.listdir('D:\毕设\ACE中文手写字识别\HWDB2.2Train_images')
for file in file_dir:
file_path = os.path.join('D:\毕设\ACE中文手写字识别\HWDB2.2Train_images',file)
img = Image.open(file_path)
print(img)
PIL:图片预处理(批量改变图片尺寸)
于 2022-04-10 11:45:47 首次发布