## image resizer
# 批量resize
import numpy as np
import cv2
import os
dir_path = os.path.join(os.getcwd(), 'D:/EZ/Segmentation/512/512_original') #要处理的的图像所在的文件夹,也可以是绝对路径
# 这样调用时,图像所在的文件夹(bdz_image)与程序在同一目录下
for filename in os.listdir(dir_path):
# If the images are not .JPG images, change the line below to match the image type.
if filename.endswith(".jpg"):
name = os.path.join(dir_path,filename) #要resize的图像的名字
image = cv2.imread(name)
resized = cv2.resize(image,None,fx=0.664935, fy=0.664935, interpolation=cv2.INTER_AREA)
re_dir_path = os.path.join(os.getcwd(), 'D:/EZ/Segmentation/512/512_json_output', filename)# 存储resize后的文件夹,也可以是绝对路径
cv2.imwrite(re_dir_path,resized)
python图片批量Resize切换大小
最新推荐文章于 2024-07-16 16:10:04 发布