Powerboxes
utility functions to manipulate and compute metrics on boxes
Install / Use
/learn @Smirkey/PowerboxesREADME
<div align="center"> PowerBoxes </div>
Powerboxes is a package containing utility functions for transforming bounding boxes and computing metrics. It is implemented in both Python and Rust. It shows a significant speedup over the equivalent numpy implementations in Python, or other libraries such as shapely or torchvision.
Checkout out the documentation !
🦀 Rust documentation
🐍 Python documentation
Installation
Python
pip install powerboxes
Rust
cargo add powerboxesrs
Python Usage
import powerboxes as pb
import numpy as np
# Create bounding boxes in xyxy format
boxes = np.array([[0, 0, 1, 1], [2, 2, 3, 3]], dtype=np.float64)
# Compute areas
areas = pb.boxes_areas(boxes)
# Compute pairwise IoU distance matrix
iou = pb.iou_distance(boxes, boxes)
# Non-maximum suppression
scores = np.array([0.9, 0.8])
keep = pb.nms(boxes, scores, iou_threshold=0.5, score_threshold=0.3)
# Draw boxes on an image (CHW format, uint8)
image = np.zeros((3, 100, 100), dtype=np.uint8)
draw_boxes = np.array([[10.0, 10.0, 50.0, 50.0]])
result = pb.draw_boxes(image, draw_boxes, filled=True, opacity=0.35)
# Draw rotated boxes in cxcywha format
rotated_boxes = np.array([[50.0, 50.0, 30.0, 20.0, 30.0]])
rotated = pb.draw_rotated_boxes(image, rotated_boxes)
Use it in Rust
All core functions use a slice-based API. ndarray wrappers are available behind the ndarray feature (enabled by default).
use powerboxesrs::iou::iou_distance_slice;
let boxes1 = vec![0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0];
let boxes2 = vec![0.5, 0.5, 1.5, 1.5, 2.5, 2.5, 3.5, 3.5];
let iou = iou_distance_slice(&boxes1, &boxes2, 2, 2);
Benchmarks
Some benchmarks of powerboxes against various open source alternatives, not all functions are benchmarked. Notice that we use log scales, all differences are major ! Benchmarks can be found in this google colab notebook
Box area
Here it's torchvision vs powerboxes vs numpy

Box convert
Here it's torchvision vs powerboxes

Box IoU matrix
Torchvision vs numpy vs powerboxes

NMS
Torchvision vs powerboxes vs lsnms vs numpy
Large image (10000x10000 pixels)

Normal image (1000x1000 pixels)

