使用 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+ 瀏覽

開啟你的 職業生涯

完成課程,獲得認證

立即開始
廣告