ในโปรแกรมนี้ เราจะวาดรูปหลายเหลี่ยมที่เติมโดยใช้ฟังก์ชัน 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) ผลลัพธ์
