Out of the Box
"I like to get into boxes."
A comprehensive toolkit for handling bounding boxes in various formats, including a GUI for ROI selection. For those who like to think out of the box.
Features
-
Bounding box utilities:
- Support for VOC, COCO, and YOLO formats
- Conversion between formats
- Area calculation
- Intersection over Union (IoU) calculation
- Drawing bounding boxes on images
-
Roy app:
- Load any image file supported by PIL
- Draw and adjust bounding box interactively
- Display coordinates in both pixel and normalized formats
- Real-time updates of bounding box parameters
Installation
pip install out-of-the-box
Usage
Bounding box utilities
img_shape = (500, 500)
img = np.zeros((*img_shape, 3), dtype=np.uint8)
# Create bounding boxes in different formats
voc_box = VOCBox(100, 100, 300, 300)
coco_box = COCOBox(100, 100, 200, 200)
yolo_box = YOLOBox(0.4, 0.4, 0.2, 0.2)
bb_voc = BoundingBox(voc_box, img_shape)
bb_coco = BoundingBox(coco_box, img_shape)
bb_yolo = BoundingBox(yolo_box, img_shape)
# Print bounding boxes
print("VOC bounding box:", bb_voc)
print("COCO bounding box:", bb_coco)
print("YOLO bounding box:", bb_yolo)
# Convert between formats
print("\nFormat conversions:")
print("VOC to COCO:", bb_voc.to_coco())
print("COCO to YOLO:", bb_coco.to_yolo())
print("YOLO to VOC:", bb_yolo.to_voc())
# Normalized and pixel coordinates
print("\nNormalized and pixel coordinates:")
print("VOC (normalized):", bb_voc.to_voc(normalized=True))
print("COCO (pixel):", bb_yolo.to_coco(normalized=False))
# Area calculation
print("\nAreas:")
print("VOC box area:", bb_voc.area)
print("COCO box area:", bb_coco.area)
print("YOLO box area:", bb_yolo.area)
# Intersection and Union
intersection = BoundingBox.intersection(bb_voc, bb_coco)
union = BoundingBox.union(bb_voc, bb_coco)
print("\nIntersection and Union:")
print(f"Intersection between VOC and COCO: {intersection:.2f}")
print(f"Union between VOC and COCO: {union:.2f}")
# IoU calculation
iou = BoundingBox.iou(bb_voc, bb_coco)
print(f"IoU between VOC and COCO boxes: {iou:.2f}")
# Percentage inside
percentage = bb_coco.percentage_inside(bb_voc)
print(f"\nPercentage of COCO box inside VOC box: {percentage:.2%}")
# Center point
print("\nCenter points:")
print("VOC box center:", bb_voc.center)
print("COCO box center:", bb_coco.center)
print("YOLO box center:", bb_yolo.center)
# Contains point
test_point = (200, 200)
print(f"\nPoint {test_point} contained in:")
print("VOC box:", bb_voc.contains_point(test_point))
print("COCO box:", bb_coco.contains_point(test_point))
print("YOLO box:", bb_yolo.contains_point(test_point))
# Overlap percentage
overlap = bb_coco.overlap_percentage(bb_voc)
print(f"\nOverlap percentage of COCO box with VOC box: {overlap:.2%}")
# Draw the bounding boxes on the image
img = bb_voc.draw_on_image(img, color=COLOR_RED, thickness=2, label="VOC")
img = bb_coco.draw_on_image(img, color=COLOR_GREEN, thickness=2, label="COCO")
img = bb_yolo.draw_on_image(img, color=COLOR_BLUE, thickness=2, label="YOLO")
# Display the image
cv2.imshow("Image with bounding boxes", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Roy App
To start the ROI selector GUI:
roy
In the GUI:
- Click "Open Image" to load an image.
- Draw a bounding box by clicking and dragging on the image.
- Adjust the box using the entry fields or by dragging.
- View both pixel and normalized coordinates.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for out-of-the-box 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| out_of_the_box-1.3.0.tar.gz | 10.7 kB | Without provenance | Details for out_of_the_box-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| out_of_the_box-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for out_of_the_box-1.3.0-py3-none-any.whl |
Total release size: 23.0 kB
Release files / out_of_the_box-1.3.0.tar.gz
| Download URL | out_of_the_box-1.3.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7512d3e3b731b3710073a81600a398ff84d82587af9cb36517efaf7d8baa86fc
|
|
BLAKE2b-256 checksum How to use checksums |
0af491cd2ad55b780905b845c47b5e81ee6b179dd1885a5f71f0720acf8cfdec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / out_of_the_box-1.3.0-py3-none-any.whl
| Download URL | out_of_the_box-1.3.0-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
428ab5e8bba0394dadc43afca61b8cd9a59e7dc61ed597329de322e019f20e38
|
|
BLAKE2b-256 checksum How to use checksums |
ae9ab2715f7838be898decd8c6c45838fe5a1eeb593d261b97719a7464c5ed55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for out-of-the-box 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.