opencv-python画直线、圆、矩形、椭圆形、多边形以及参数介绍
cv2.line(img,pt1,pt2,color,thickness)
实现代码:
img = np.zeros((200,200,3), dtype=np.uint8)
img = cv2.line(img, (25, 189), (99, 18), (0, 0, 255), 2)
cv2.circle(img,center,radius,color, thickness)
当不填充圆形时:
img = np.zeros((200,200,3), dtype=np.uint8)
img = cv2.circle(img,(100,100), 63, (100,0,255), 2)#最后一个参数代表线宽
img = np.zeros((200,200,3), dtype=np.uint8)
img = cv2.circle(img,(100,100), 63, (100,0,255), -1)# 最后一个参数为-1时,表示填充
cv2.rectangle(img, pt1, pt2, color, thicknes)
实现代码:
img = np.zeros((170,200,3), dtype=np.uint8)
img = cv2.rectangle(img,(32,10),(168,128),(0,255,0),3)
cv2.ellipse(img,center, axes,angle,startAngle,endAngle,color,thickness)
实现代码:
img = np.zeros((200,200,3), dtype=np.uint8)
img = cv2.ellipse(img,(100,100),(80,30),100,-180,180,(100,0,255),-1)
cv2.polylines(img, pts, isClosed, color, thickness)
实现代码:
img = np.zeros((200,200,3), dtype=np.uint8)
pts = np.array([[20, 10], [40, 180], [140, 140], [80, 20]], np.int32)
pts = pts.reshape((-1, 1, 2))
img = cv2.polylines(img,pts=[pts],isClosed=True, color=(0, 0, 200), thickness=2)
Image.fromarray(img)
cv2.fillPoly(img, pts, color)
实现代码:
img = np.zeros((200,200,3), dtype=np.uint8)
pts = np.array([[20, 10], [40, 180], [140, 140], [80, 20]], np.int32)
pts = pts.reshape((-1, 1, 2))
img = cv2.fillPoly(img,[pts],(255,255,255))
Image.fromarray(img)