import cv2
import numpy as np
#512*512的黑色背景图
img = np.zeros((512,512,3),np.uint8)
#-----------------------------------------------------------------
#绘制直线
cv2.line(img,(0,0),(511,511),(255,0,0),5)
#-----------------------------------------------------------------
#绘制矩阵 -1为填充
cv2.rectangle(img,(384,0),(511,511),(255,0,0),1)
#-----------------------------------------------------------------
#绘制圆形 -1为填充
cv2.circle(img,(447,63),63,(0,0,255),-1)
#-----------------------------------------------------------------
#绘制椭圆 -1为填充
cv2.ellipse(img,(256,256),(100,50),0,0,360,(255,0,0),-1)
#-----------------------------------------------------------------
#绘制多边形
pts = np.array([[10,5],[50,10],[70,20],[20,30]])
pts = pts.reshape((-1,1,2))#-1为自动匹配顶点数
cv2.polylines(img,[pts],True,(0,255,255))#True为线段闭合,False为不闭合
cv2.imshow('d',img)
cv2.waitKey(0)
cv2.destroyAllWindows