4, opencv基础api学习-绘图练习

181 阅读1分钟

# coding:utf-8
import  cv2
import numpy as np



def show(img):
    # cv2.namedWindow('aa', cv2.WINDOW_NORMAL)
    cv2.imshow('aa', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

img = np.zeros((500, 500, 3), np.uint8)
# 线
cv2.line(img, (0,0),(500, 500), (255, 0, 0), 2)
# 多边形
pts = np.array([[50, 10],[100, 20],[180,80],[70, 90]],np.int32)
pts.reshape((-2, 1, 2))
cv2.polylines(img, [pts], True, (255, 255, 255))
# 矩形
cv2.rectangle(img, (400, 0), (500, 100), (0,255, 0), 2)
#  圆
cv2.circle(img, (450, 50), 50, (0, 0, 255), -1)
# 椭圆
cv2.ellipse(img, (250, 250), (100, 50), 0, 0, 180, (255, 0 ,0),-1)
# 写字
cv2.putText(img, 'OpenCV', (0, 450), cv2.FONT_HERSHEY_DUPLEX, 4, (255, 255, 255), 4, cv2.LINE_AA, False)


show(img)