python对文件夹下的所有图片进行裁剪

from PIL import Image
import os


dir_root = "./depth"
files = os.listdir(dir_root)
for file_name in files:
    img = Image.open(os.path.join(dir_root, file_name))
    # cropped1 = img.crop((350, 250, 1200, 1400))  # (left, upper, right, lower)
    # cropped1 = cropped1.resize((850, 1100))
    # cropped1.save("./img_out/" + file_name)

    # cropped1 = img.crop((2200, 400, 3050, 1350))  # (left, upper, right, lower)
    # cropped1 = cropped1.resize((850, 1100))
    # cropped1.save("./ske_out/" + file_name)

    cropped1 = img.crop((900, 350, 1750, 950))  # (left, upper, right, lower)
    cropped1 = cropped1.resize((850, 1100))
    cropped1.save("./depth_out/" + file_name)

你可能感兴趣的:(Python)