使用 OpenCV 函数 fillPoly() 绘制一个填充多边形


在本程序中,我们将使用 opencv 函数 fillPoly() 绘制一个填充多边形。该函数需要图像和多边形的端点。

算法

Step 1: Import cv2 and numpy.
Step 2: Define the endpoints.
Step 3: Define the image using zeros.
Step 4: Draw the polygon using the fillpoly() function.
Step 5: Display the output.

示例代码

import cv2
import numpy as np
contours = np.array([[50,50], [50,150], [150,150], [150,50]])
image = np.zeros((200,200))
cv2.fillPoly(image, pts = [contours], color =(255,255,255))
cv2.imshow("filledPolygon", image)

输出

更新日期:17-Mar-2021

7K+ 浏览

开启你的 职业生涯

完成课程,获得认证

立即开始
广告
© . All rights reserved.