import cv2 import os image_size_h = 512 # 设定宽 image_size_w = 512 # 设定长 source_path = r'C:/Users/lirui/Desktop/crop/' # 源文件路径 target_path = r'C:/Users/lirui/Desktop/resize_crop/' # 输出目标文件路径 if not os.path.exists(target_path): os.makedirs(target_path) image_list = os.listdir(source_path) # 获得文件名 i = 0 for file in image_list: i = i + 1 image_source = cv2.imread(source_path + file) # 读取图片 print("num:", i) image = cv2.resize(image_source, (image_size_w, image_size_h), 0, 0, cv2.INTER_LINEAR) # 修改尺寸 cv2.imwrite(target_path + file , image) # 重命名并且保存 print("批量处理完成")
resize
最新推荐文章于 2022-11-24 14:53:10 发布