Different ways of visualizing objects given bounding box data
Project description
bbox-visualizer
This package helps users draw bounding boxes around objects, without doing the clumsy math that you'd need to do for positioning the labels. It also has a few different types of visualizations you can use for labeling objects after identifying them.
By default the bounding box points are expected in Pascal VOC format: (xmin, ymin, xmax, ymax). COCO and YOLO formats are also supported via the bbox_format keyword argument (see Bounding box formats).
- Documentation: https://bbox-visualizer.readthedocs.io.
- Free software: MIT license
Installation:
pip install bbox-visualizer
Quick Start
A complete example that loads an image, draws a labeled bounding box, and saves the result:
import cv2
import bbox_visualizer as bbv
img = cv2.imread("path/to/image.jpg")
# Bounding boxes use [x_min, y_min, x_max, y_max]
bbox = [150, 100, 450, 300]
label = "person"
img = bbv.draw_box(img, bbox, bbox_color=(0, 255, 0))
img = bbv.add_label(img, label, bbox)
cv2.imwrite("output.jpg", img)
All functions return a new image and never modify the input image, so keep the return value (as above) rather than relying on in-place changes.
For multiple objects, use the _multiple_ variants with parallel lists:
bboxes = [[150, 100, 450, 300], [500, 50, 700, 250]]
labels = ["person", "dog"]
img = bbv.draw_multiple_boxes(img, bboxes)
img = bbv.add_multiple_labels(img, labels, bboxes)
draw_multiple_boxes also accepts one color per box:
img = bbv.draw_multiple_boxes(img, bboxes, bbox_color=[(0, 255, 0), (0, 0, 255)])
The library logs fallback warnings (e.g., when a label doesn't fit) through
Python's logging module. To silence them:
import logging
logging.getLogger("bbox_visualizer").setLevel(logging.ERROR)
Bounding box formats
Every drawing function accepts a bbox_format keyword argument. The default is
Pascal VOC.
bbox_format |
Coordinates | Scale |
|---|---|---|
"voc" (default) |
[x_min, y_min, x_max, y_max] |
absolute pixels |
"coco" |
[x_min, y_min, width, height] |
absolute pixels |
"yolo" |
[x_center, y_center, width, height] |
normalized to [0, 1] |
# COCO format: [x_min, y_min, width, height]
img = bbv.draw_box(img, [150, 100, 300, 200], bbox_format="coco")
# YOLO format: [x_center, y_center, width, height], normalized to [0, 1].
# Image dimensions are read from the image, so no extra arguments are needed.
img = bbv.draw_box(img, [0.5, 0.4, 0.3, 0.25], bbox_format="yolo")
# Works with the multiple-object variants too
img = bbv.draw_multiple_boxes(img, coco_bboxes, bbox_format="coco")
Internally all formats are converted to Pascal VOC before drawing.
Runnable scripts live in examples/:
quickstart.py— minimal example on a blank canvassingle_object.py— every single-object label stylemultiple_objects.py— every multi-object label stylelabel_stress.py— awkward label strings through every style, for eyeballing label layout
Photos by Joshua Earle, Jonas Weckschmied and Sherzod Max on Unsplash.
| image | function |
|---|---|
| img = bbv.draw_box(img, bbox) img = bbv.add_label(img, label, bbox, top=True) |
|
| img = bbv.draw_box(img, bbox) img = bbv.add_T_label(img, label, bbox) |
|
| img = bbv.draw_flag_with_label(img, label, bbox) | |
| img = bbv.draw_box(img, bbox) img = bbv.add_label(img, label, bbox, top=False) |
|
| img = bbv.draw_box(image, bbox, is_opaque=True) img = bbv.add_label(img, label, bbox, draw_bg=False, top=False) |
|
| img = bbv.draw_multiple_boxes(img, bboxes) img = bbv.add_multiple_labels(img, labels, bboxes) |
|
| img = bbv.draw_multiple_flags_with_labels(img, labels, bboxes) | |
| img = bbv.draw_multiple_boxes(img, bboxes) img = bbv.add_multiple_T_labels(img, labels, bboxes) |
Note: The functions
draw_rectangleanddraw_multiple_rectanglesare also available as aliases fordraw_boxanddraw_multiple_boxesrespectively. Both naming conventions work identically.
Tip: The
draw_multiple_*andadd_multiple_*functions are convenience helpers. For full control over your visualizations, call the single-box functions (draw_box,add_label, etc.) in a loop instead.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bbox_visualizer-1.0.1.tar.gz.
File metadata
- Download URL: bbox_visualizer-1.0.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7216e5582d0f214c31dbf47b91354924c6f80b41ed52458a43fb5d4c30f4104a
|
|
| MD5 |
9e87dd0bac693664b9faf1572fe685a1
|
|
| BLAKE2b-256 |
fb7a88965f56ddd45782cd7026cdbc8a7131ff2d99d93ee26ab7445d7c99bfe0
|
Provenance
The following attestation bundles were made for bbox_visualizer-1.0.1.tar.gz:
Publisher:
publish.yml on shoumikchow/bbox-visualizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bbox_visualizer-1.0.1.tar.gz -
Subject digest:
7216e5582d0f214c31dbf47b91354924c6f80b41ed52458a43fb5d4c30f4104a - Sigstore transparency entry: 2191770847
- Sigstore integration time:
-
Permalink:
shoumikchow/bbox-visualizer@180edea0b2851dec985c3aa952809d4f6ecafc63 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/shoumikchow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@180edea0b2851dec985c3aa952809d4f6ecafc63 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bbox_visualizer-1.0.1-py3-none-any.whl.
File metadata
- Download URL: bbox_visualizer-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b24af917d785aae0657703933f380d66d9da5daee9e4a9d0b0cfc08f98715bdc
|
|
| MD5 |
52e58429ff71229fd860ed1d65bff727
|
|
| BLAKE2b-256 |
6b64ff2f6153671b08d99f6d5b48a728edc14726711a4bd6e5fc796c41f5b812
|
Provenance
The following attestation bundles were made for bbox_visualizer-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on shoumikchow/bbox-visualizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bbox_visualizer-1.0.1-py3-none-any.whl -
Subject digest:
b24af917d785aae0657703933f380d66d9da5daee9e4a9d0b0cfc08f98715bdc - Sigstore transparency entry: 2191770873
- Sigstore integration time:
-
Permalink:
shoumikchow/bbox-visualizer@180edea0b2851dec985c3aa952809d4f6ecafc63 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/shoumikchow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@180edea0b2851dec985c3aa952809d4f6ecafc63 -
Trigger Event:
release
-
Statement type: