Skip to main content

A bounding box visualizer

Project description

BBox-Visualizer2

This is a python package for visualizing bounding boxes and adding labels to a given image. The creation of this package is inspired by shoumikchow/bbox-visualizer, but I re-implement it through Pillow instead of cv2.

The format of a bounding box is (xmin, ymin, xmax, ymax).

Installation

From Pypi

pip install bbox-visualizer2

From source

git clone https://github.com/fansuregrin/bbox-visualizer2.git bbv2
cd bbv2
python3 -m pip install --upgrade build
python3 -m build
pip install dist/bbox_visualizer2-0.0.2-py3-none-any.whl

Usage

You can see demos for details.

Multiple bboxes visualization

Code examples

classes = [
    'person', 'bird',
    'cat', 'cow',
    'dog', 'horse',
    'sheep', 'aeroplane',
    'bicycle', 'boat',
    'bus', 'car',
    'motorbike', 'train',
    'bottle', 'chair',
    'diningtable', 'pottedplant',
    'sofa', 'tvmonitor',
]
font_path = 'assets/fonts/LXGWWenKai-Regular.ttf'
img_path = 'assets/images/000623.jpg'
pil_img = Image.open(img_path)
img = np.asarray(pil_img, dtype=np.uint8)
xml_filepath = 'assets/annotations/000623.xml'
boxes, labels = get_annot_info(xml_filepath, classes)

bbox_visualizer = bbv.BBoxVisualizer(classes, font_path)
img = bbox_visualizer.visualize_bbox(img, boxes, labels)

Single bbox visualization

(1) Label on the top of the bbox

Code examples

label = 'cow'
box = [299, 160, 446, 252]
color = (255, 255, 0)
text_color = (0, 0, 0)

img1 = bbv.draw_rectangle(img, box, bbox_color=color, thickness=1)
img1 = bbv.add_label(img1, label, box, size=12, draw_bg=True,
                     text_bg_color=color, alpha=0.5, text_color=text_color,
                     top=True, font_fp=font_path)

(2) Label inside the box

Code examples

label = 'cow'
box = [299, 160, 446, 252]
color = (255, 255, 0)
text_color = (0, 0, 0)

img2 = bbv.draw_rectangle(img, box, bbox_color=color, thickness=3)
img2 = bbv.add_label(img2, label, box, size=12, draw_bg=True,
                     text_bg_color=color, alpha=0.5, text_color=text_color,
                     top=False, font_fp=font_path)

(3) Set the box to opaque

Code examples

label = 'cow'
box = [299, 160, 446, 252]
color = (255, 255, 0)
text_color = (0, 0, 0)

img3 = bbv.draw_rectangle(img, box, bbox_color=color, is_opaque=True, alpha=0.5)
img3 = bbv.add_label(img3, label, box, size=12, draw_bg=True,
                     text_bg_color=color, alpha=0.5, text_color=text_color,
                     top=False, font_fp=font_path)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bbox_visualizer2-0.0.4.tar.gz (12.8 MB view details)

Uploaded Source

Built Distribution

bbox_visualizer2-0.0.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file bbox_visualizer2-0.0.4.tar.gz.

File metadata

  • Download URL: bbox_visualizer2-0.0.4.tar.gz
  • Upload date:
  • Size: 12.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for bbox_visualizer2-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a2b6568b68f8a4557ef16579a44efcfd58dc35649962ce0cfff0305616c5e28b
MD5 34f17fb89ee0aa1564a23f043cd640ad
BLAKE2b-256 6ab1c25d887263c3458523a852bfcb3592e9a2708571247d92e39b61c96e3425

See more details on using hashes here.

File details

Details for the file bbox_visualizer2-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for bbox_visualizer2-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 dc33cd4240ba84bf12b71dafd9168445fd6632b7a6d5f8efd1f6a6c5cb937ea8
MD5 8c76989defbe3fc628ece3c078b6470c
BLAKE2b-256 911b777ceafe97841450dd045fd128ac31b6d696f16b4571284452a53ca1cf8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page