Esempio n. 1
0
def paint_voronoi( subdiv, img ):
    cv.CalcSubdivVoronoi2D( subdiv );
    for edge in subdiv.edges:
        # left
        draw_subdiv_facet( img, cv.Subdiv2DRotateEdge( edge, 1 ));
       # right
        draw_subdiv_facet( img, cv.Subdiv2DRotateEdge( edge, 3 ));
Esempio n. 2
0
def draw_subdiv_facet(img, edge):

    t = edge
    count = 0

    # count number of edges in facet
    while count == 0 or t != edge:
        count += 1
        t = cv.Subdiv2DGetEdge(t, cv.CV_NEXT_AROUND_LEFT)

    buf = []

    # gather points
    t = edge
    for i in range(count):
        assert t > 4
        pt = cv.Subdiv2DEdgeOrg(t)
        if not pt:
            break
        buf.append((cv.Round(pt.pt[0]), cv.Round(pt.pt[1])))
        t = cv.Subdiv2DGetEdge(t, cv.CV_NEXT_AROUND_LEFT)

    if (len(buf) == count):
        pt = cv.Subdiv2DEdgeDst(cv.Subdiv2DRotateEdge(edge, 1))
        cv.FillConvexPoly(
            img, buf,
            cv.RGB(random.randrange(256), random.randrange(256),
                   random.randrange(256)), cv.CV_AA, 0)
        cv.PolyLine(img, [buf], 1, cv.RGB(0, 0, 0), 1, cv.CV_AA, 0)
        draw_subdiv_point(img, pt.pt, cv.RGB(0, 0, 0))
Esempio n. 3
0
def draw_subdiv(img, subdiv, delaunay_color, voronoi_color):

    for edge in subdiv.edges:
        edge_rot = cv.Subdiv2DRotateEdge(edge, 1)

        draw_subdiv_edge(img, edge_rot, voronoi_color)
        draw_subdiv_edge(img, edge, delaunay_color)