1. 使用Pillow库:
from PIL import Image, ImageDraw加载图像image = Image.open("example.jpg")创建画布对象draw = ImageDraw.Draw(image)绘制方框draw.rectangle((x1, y1, x2, y2), outline="red", width=2)保存和显示图像image.save("output.jpg")image.show()

2. 使用OpenCV库:
import cv2读取图像image = cv2.imread("example.jpg")绘制方框cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)保存和显示图像cv2.imshow("image", image)cv2.waitKey(0)cv2.destroyAllWindows()
请根据您的需求选择合适的库和代码示例。
