"""
试用opencv创建画布并显示矩形框(适用于目标检测图像可视化)
"""
# 创建一个黑色的画布,图像格式(BGR)
img = np.zeros((512, 512, 3), np.uint8)
# 画一个矩形:给定左上角和右下角坐标(宽度,高度)---> pt1=(15, 15), pt2=(50, 320)
cv2.rectangle(img, pt1=(15, 15), pt2=(50, 320), color=(255, 0, 0), thickness=8)
# 可视化
cv2.imshow('image', img)
cv2.waitKey(0)
# 释放资源
cv2.destroyWindows('image')
"""
试用opencv创建画布并显示圆形内容
"""
# 创建一个黑色的画布
img0 = np.zeros((512,512,3), np.uint8)
# 设置圆的参数,进行画圆 参数定义: 给定椭圆的圆心、轴长、偏移的角度、以及椭圆的角度信息
cv2.ellipse(img0, center=(210, 310), color=(255, 0, 0), axes=(100, 50), angle=0, startAngle=0, endAngle=180, thickness=8)
cv2.ellipse(img0, center=(110, 110), color=(0, 255, 0), axes=(100, 50), angle=30, startAngle=0, endAngle=180, thickness=8)
cv2.ellipse(img0, center=(310, 110), color=(0, 0, 255), axes=(10, 50), angle=0, startAngle=0, endAngle=360, thickness=-1)
cv2.ellipse(img0, center=(210, 210), color=(0, 0, 255), axes=(50, 50), angle=0, startAngle=0, endAngle=180, thickness=-1)
cv2.ellipse(img0, center=(410, 410), color=(255, 255, 0), axes=(50, 50), angle=0, startAngle=0, endAngle=180, thickness=10)
cv2.rectangle(img0, pt1=(360, 410), pt2=(460, 410), color=(255, 255, 0), thickness=10)
# 可视化
cv2.imshow('IMG', img0)
cv2.waitKey(0)
# 释放资源
cv2.destroyWindow('IMG')
"""
试用opencv创建画布并显示多边型
"""
# 创建一个黑色的画布
img2 = np.zeros((512, 512, 3), np.uint8)
# 画多边形
pts = np.array([
[10,5],
[20,50],
[70,80],
[50,10],
], np.int32)
print('the shape of pts:', pts.shape)
pts = pts.reshape((-1,1,2))
print('the reshape of pts:', pts.shape)
cv2.polylines(img2, [pts], isClosed=False, color=(255, 0, 255), thickness=8, lineType=cv2.LINE_4)
# 添加文本
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img2, text='Do IT!', org=(50,250), fontFace=font, fontScale=5, color=(0, 255, 0), thickness=8, lineType=cv2.LINE_AA)
# 可视化
cv2.imshow('Image2', img2)
cv2.waitKey(0)
cv2.destroyWindow('Image2')