赞
踩
源代码如下:ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
主要的参数如下:
[(x0, y0), (x1, y1)]
或者 [x0, y0, x1, y1]
# importing image object from PIL
import math
from PIL import Image, ImageDraw
img = Image.open("Gym.jpg")
ImageDraw.Draw(img).rectangle([(100, 300), (300, 700)] , fill =None, outline ="red",width =2)
plt.imshow(img)
plt.show()
截图如下:
cv2.rectangle 则根据对角线画矩形
示例代码如下:
import os
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("Gym.jpg")
xmin = 100
xmax = 500
ymin = 100
ymax = 800
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0,0,255), 2)
cv2.rectangle(img, (xmin, ymax), (xmax, ymin), (255,0,0), 2)
# cv2.imshow('src',img)
# cv2.waitKey()
plt.imshow(img)
plt.show()
截图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。