How to use the labelme.utils.draw_instances function in labelme

To help you get started, we’ve selected a few labelme 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 / labelme / tests / test_utils.py View on Github external
def test_draw_instances():
    img, lbl, label_names = _get_img_and_lbl()
    labels_and_masks = {l: lbl == l for l in np.unique(lbl) if l != 0}
    labels, masks = zip(*labels_and_masks.items())
    masks = np.asarray(masks)
    bboxes = labelme.utils.masks_to_bboxes(masks)
    captions = [label_names[l] for l in labels]
    viz = labelme.utils.draw_instances(img, bboxes, labels, captions=captions)
    assert viz.shape[:2] == img.shape[:2]
    assert viz.dtype == np.uint8
github veraposeidon / labelme2Datasets / dataset_split_region.py View on Github external
maker.name(class_name),  # label name
                maker.pose(""),  # pose info, doesn't matter
                maker.truncated("0"),  # truncated info, doesn't matter
                maker.difficult("0"),  # diificulty, doesn't matter
                maker.bndbox(  # bbox(up-left corner and bottom-right corner points)
                    maker.xmin(str(xmin)),
                    maker.ymin(str(ymin)),
                    maker.xmax(str(xmax)),
                    maker.ymax(str(ymax)),
                ),
            )
        )

    # caption for visualize drawing
    captions = [class_names[l] for l in labels]
    viz = labelme.utils.draw_instances(
        img, bboxes, labels, captions=captions
    )

    PIL.Image.fromarray(viz).save(out_viz_file)

    # another visualize format (colored mask in bbox)
    label_name_to_value = {'_background_': 0}
    for shape in sorted(region['objects'], key=lambda x: x['name']):
        label_name = shape['name']

        if label_name in label_name_to_value:
            label_value = label_name_to_value[label_name]
        else:
            label_value = len(label_name_to_value)
            label_name_to_value[label_name] = label_value
github veraposeidon / labelme2Datasets / bbox_labelme2voc.py View on Github external
maker.name(class_name),  # label name
                    maker.pose(""),  # pose info, doesn't matter
                    maker.truncated("0"),  # truncated info, doesn't matter
                    maker.difficult("0"),  # diificulty, doesn't matter
                    maker.bndbox(  # bbox(up-left corner and bottom-right corner points)
                        maker.xmin(str(xmin)),
                        maker.ymin(str(ymin)),
                        maker.xmax(str(xmax)),
                        maker.ymax(str(ymax)),
                    ),
                )
            )

        # caption for visualize drawing
        captions = [class_names[l] for l in labels]
        viz = labelme.utils.draw_instances(
            img, bboxes, labels, captions=captions
        )

        PIL.Image.fromarray(viz).save(out_viz_file)

        # another visualize format (colored mask in bbox)
        label_name_to_value = {'_background_': 0}
        for shape in sorted(data['shapes'], key=lambda x: x['label']):
            label_name = shape['label']

            if label_name in label_name_to_value:
                label_value = label_name_to_value[label_name]
            else:
                label_value = len(label_name_to_value)
                label_name_to_value[label_name] = label_value