cv2.fillConvexPoly
Rellena el interior del polígono con valores.
Primero realice la detección de bordes y complete los objetivos pequeños:
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
for num in range(len(contours)):
if (cv2.contourArea(contours[num]) < 200):
print("fill")
# cv2.drawContours(image, contours[num], -1, (0, 255, 0), 2)
cv2.fillConvexPoly(thresh, contours[num], 255)
if len(contours)>0:
cv2.imshow("thresh2", thresh)
El diagrama de un solo canal puede:
import numpy as np
import cv2
img = np.zeros((680, 920), np.uint8)
triangle = np.array([[0, 0], [500, 800], [500, 400]])
cv2.fillConvexPoly(img, triangle, 255)
# cv2.fillConvexPoly(img, triangle, (255, 255, 255))
cv2.imshow("'asdf",img)
cv2.waitKey()
El multicanal también puede:
La función cv2.fillConvexPoly () se puede usar para rellenar polígonos convexos, solo proporcione los vértices del polígono convexo.
Dibujemos un triangulo
img = np.zeros((1080, 1920, 3), np.uint8)
triangle = np.array([[0, 0], [1500, 800], [500, 400]])
cv2.fillConvexPoly(img, triangle, (255, 255, 255))
cv2.imshow("'asdf",img)
cv2.waitKey(
cv2.fillPoly ()
La función cv2.fillPoly () se puede usar para rellenar gráficos de cualquier forma. Se puede usar para dibujar polígonos, y muchas aristas se usan a menudo en el trabajo para aproximar una curva. La función cv2.fillPoly () puede llenar múltiples gráficos en una vez escriba.
img = np.zeros((1080, 1920, 3), np.uint8)
area1 = np.array([[250, 200], [300, 100], [750, 800], [100, 1000]])
area2 = np.array([[1000, 200], [1500, 200], [1500, 400], [1000, 400]])
cv2.fillPoly(img, [area1, area2], (255, 255, 255))
cv2.imshow("asdf",img)
cv2.waitKey()