import numpy as np
import cv2
from PIL import Image
import matplotlib.pyplot as plt
image_Big = 'C:/Users/Lenovo/Desktop/test22/0007.png'
image_Big = Image.open(image_Big)
first_point = (20,420)
last_point = (20+300, 420+300)
print("左上角起点坐标:{0} 右下角终点坐标:{1}".format(first_point, last_point))
image_Big=cv2.rectangle(np.array(image_Big), first_point, last_point, (0, 255, 0), 2)
right_point1 = (22, 417)
right_point2 = (22 + 300, 417+300)
print(right_point1, right_point2)
image_Big2 = cv2.rectangle(image_Big, right_point1, right_point2, (0, 255, 255), 2)
plt.imshow(image_Big2)
plt.show()
在图像上加两个矩形框
最新推荐文章于 2025-12-21 18:49:56 发布
这段代码展示了如何使用OpenCV和PIL库在Python中打开图像,并在图像上绘制矩形。首先,它打开指定路径的图像,然后定义两个矩形的起始和结束点,用绿色和蓝色分别画出两个矩形。最后,使用matplotlib显示处理后的图像。
1390

被折叠的 条评论
为什么被折叠?



