import cv2
import numpy as np
# 创建一张图片
img = np.ones((500, 500, 3), np.uint8)
# 绘制线段
cv2.line(img, (60, 240), (220, 240), (0, 0, 255), 3, cv2.LINE_AA)
cv2.line(img, (140, 160), (140, 320), (0, 0, 255), 3, cv2.LINE_AA)
# 绘制矩形
cv2.rectangle(img, (100, 200), (180, 280), (0, 255, 255), 3, cv2.LINE_AA)
cv2.rectangle(img, (80, 180), (200, 300), (0, 255, 255), 3, cv2.LINE_AA)
cv2.rectangle(img, (60, 160), (220, 320), (0, 255, 255), 3, cv2.LINE_AA)
# 绘制圆形
cv2.circle(img, (140, 240), 80, (255, 255, 0), 2, cv2.LINE_AA)
cv2.circle(img, (140, 240), 60, (255, 255, 0), 2, cv2.LINE_AA)
cv2.circle(img, (140, 240), 40, (255, 255, 0), 2, cv2.LINE_AA)
# 绘制椭圆形
cv2.ellipse(img, (140, 80), (100, 50), 0, 0, 360, (0, 255, 0), 2, cv2.LINE_AA)
cv2.ellipse(img, (140, 80), (90, 40), 0, 0, 90, (255, 0, 0), 2, cv2.LINE_AA)
cv2.ellipse(img, (140, 80), (90, 40), 0, 270, 360, (0, 255, 0), 2, cv2.LINE_AA)
cv2.ellipse(img, (140, 80), (80, 30), 0, 0, 90, (0, 255, 0), 2, cv2.LINE_AA)
cv2.ellipse(img, (140, 80), (80, 30), 0, 270, 360, (255, 255, 0), 2, cv2.LINE_AA)
cv2.ellipse(img, (140, 80), (70, 20), 0, 90, 270, (255, 255, 0), 2, cv2.LINE_AA)
# 绘制多边形
pts = np.array([[400, 100], [300, 140], [450, 250], [350, 250]], np.int32)
cv2.polylines(img, [pts], True, (0, 0, 255), 1, cv2.LINE_AA)
# 绘制文字
cv2.putText(img, 'r8c OpenCV', (0, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 4)
cv2.imshow(" Image ", img)
cv2.waitKey(0)