How to use the imgviz.draw.rectangle function in imgviz

To help you get started, we’ve selected a few imgviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wkentaro / imgviz / imgviz / label.py View on Github external
)
        text_height, text_width = text_sizes.max(axis=0)
        legend_height = text_height * len(unique_labels) + 5
        legend_width = text_width + 20 + (text_height - 10)

        height, width = label.shape[:2]
        legend = np.zeros((height, width, 3), dtype=np.uint8)
        if loc == "rb":
            aabb2 = np.array([height - 5, width - 5], dtype=float)
            aabb1 = aabb2 - (legend_height, legend_width)
        elif loc == "lt":
            aabb1 = np.array([5, 5], dtype=float)
            aabb2 = aabb1 + (legend_height, legend_width)
        else:
            raise ValueError("unexpected loc: {}".format(loc))
        legend = draw_module.rectangle(
            legend, aabb1, aabb2, fill=(255, 255, 255)
        )

        alpha = 0.5
        y1, x1 = aabb1.round().astype(int)
        y2, x2 = aabb2.round().astype(int)
        res[y1:y2, x1:x2] = (
            alpha * res[y1:y2, x1:x2] + alpha * legend[y1:y2, x1:x2]
        )

        for i, l in enumerate(unique_labels):
            box_aabb1 = aabb1 + (i * text_height + 5, 5)
            box_aabb2 = box_aabb1 + (text_height - 10, text_height - 10)
            res = draw_module.rectangle(
                res, aabb1=box_aabb1, aabb2=box_aabb2, fill=colormap[l]
            )
github wkentaro / imgviz / imgviz / label.py View on Github external
raise ValueError("unexpected loc: {}".format(loc))
        legend = draw_module.rectangle(
            legend, aabb1, aabb2, fill=(255, 255, 255)
        )

        alpha = 0.5
        y1, x1 = aabb1.round().astype(int)
        y2, x2 = aabb2.round().astype(int)
        res[y1:y2, x1:x2] = (
            alpha * res[y1:y2, x1:x2] + alpha * legend[y1:y2, x1:x2]
        )

        for i, l in enumerate(unique_labels):
            box_aabb1 = aabb1 + (i * text_height + 5, 5)
            box_aabb2 = box_aabb1 + (text_height - 10, text_height - 10)
            res = draw_module.rectangle(
                res, aabb1=box_aabb1, aabb2=box_aabb2, fill=colormap[l]
            )
            res = draw_module.text(
                res,
                yx=aabb1 + (i * text_height, 10 + (text_height - 10)),
                text=label_names[l],
                size=font_size,
                font_path=font_path,
            )
    else:
        raise ValueError("unsupported loc: {}".format(loc))

    return res
github wkentaro / imgviz / examples / draw.py View on Github external
size = 20
        color = tuple(color)
        if shape == "star":
            viz = imgviz.draw.star(
                viz, center=(xy[1], xy[0]), size=1.2 * size, fill=color
            )
        elif shape == "circle":
            viz = imgviz.draw.circle(
                viz, center=(xy[1], xy[0]), diameter=size, fill=color
            )
        elif shape == "triangle":
            viz = imgviz.draw.triangle(
                viz, center=(xy[1], xy[0]), size=size, fill=color
            )
        elif shape == "rectangle":
            viz = imgviz.draw.rectangle(
                viz,
                aabb1=(xy[1] - size / 2, xy[0] - size / 2),
                aabb2=(xy[1] + size / 2, xy[0] + size / 2),
                fill=color,
            )
        else:
            raise ValueError("unsupport shape: {}".format(shape))

    img = imgviz.draw.text_in_rectangle(
        img, loc="lt+", text="original", size=30, background=(255, 255, 255),
    )
    viz = imgviz.draw.text_in_rectangle(
        viz, loc="lt+", text="markers", size=30, background=(255, 255, 255),
    )

    # -------------------------------------------------------------------------