cv2.fillConvexPolyはポリゴンを塗りつぶします

 

cv2.fillConvexPoly

 

ポリゴンの内側に値を入力します

最初にエッジ検出を行い、小さなターゲットを埋めます。

        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)

シングルチャネル図は次のことができます。

   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()

マルチチャネルは次のこともできます。

cv2.fillConvexPoly()関数を使用して、凸多角形を塗りつぶすことができます。凸多角形の頂点を指定するだけです。

三角形を描きましょう

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()

cv2.fillPoly()関数は、任意の形状のグラフを塗りつぶすために使用できます。ポリゴンの描画に使用でき、曲線を近似するために多くのエッジが作業で使用されることがよくあります。cv2.fillPoly()関数は、次の場所で複数のグラフを塗りつぶすことができます。一度入力します。

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()

 

おすすめ

転載: blog.csdn.net/jacke121/article/details/115253207