34 lines
969 B
Python
34 lines
969 B
Python
import os
|
|
from PIL import Image, ImageDraw
|
|
|
|
|
|
IMAGE_PATH = r"d:\dsWork\aiData\Output\Screenshot_20260117_073155.jpg"
|
|
OUTPUT_PATH = r"d:\dsWork\aiData\Output\rabbit_blue_rect_20260117_073155.jpg"
|
|
|
|
|
|
def draw_rabbit_blue_rect(image_path: str, output_path: str):
|
|
if not os.path.exists(image_path):
|
|
raise FileNotFoundError(image_path)
|
|
|
|
img = Image.open(image_path).convert("RGB")
|
|
w, h = img.size
|
|
|
|
# 水平方向收一点边:左右各预留 4% 宽度
|
|
x1 = int(w * 0.04)
|
|
x2 = int(w * 0.96)
|
|
# 垂直方向:稍微向上抬一点上边界,下边界大幅向上
|
|
y1 = int(h * 0.74)
|
|
y2 = int(h * 0.86)
|
|
|
|
draw = ImageDraw.Draw(img)
|
|
draw.rectangle((x1, y1, x2, y2), outline="blue", width=4)
|
|
|
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
img.save(output_path)
|
|
print(f"saved: {output_path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
draw_rabbit_blue_rect(IMAGE_PATH, OUTPUT_PATH)
|
|
|