import os
from PIL import Image
import shutil

# ÊäÈë¡¢Êä³öÎÄ¼þ¼Ð
input_folder = "/data/share/zyh/master_dataset/dataset_net/pokou_251115_251121/to_dataset"
output_folder = "/data/share/zyh/master_dataset/dataset_net/pokou_251115_251121/resize"
os.makedirs(output_folder, exist_ok=True)

# ±éÀúÊäÈëÎÄ¼þ¼Ð
for filename in os.listdir(input_folder):
    file_path = os.path.join(input_folder, filename)
    name, ext = os.path.splitext(filename)

    if ext.lower() == ".jpg":
        # ´ò¿ªÍ¼Æ¬
        img = Image.open(file_path)
        w, h = img.size

        # ´´½¨ºÚÉ«±³¾° 2000x2000
        new_img = Image.new("RGB", (2000, 2000), (0, 0, 0))
        # ½«Ô­Í¼Õ³Ìùµ½ÉÏ·½
        new_img.paste(img, (0,0))
        # ±£´æµ½Êä³öÎÄ¼þ¼Ð
        new_img.save(os.path.join(output_folder, filename))

        # Í¬Ê±¸´ÖÆ¶ÔÓ¦ JSON ÎÄ¼þ
        json_file = os.path.join(input_folder, name + ".json")
        if os.path.exists(json_file):
            shutil.copy(json_file, os.path.join(output_folder, name + ".json"))

print("´¦ÀíÍê³É£¡")
