MCPcopy Index your code
hub / github.com/Smirkey/powerboxes

github.com/Smirkey/powerboxes @0.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.3.1 ↗ · + Follow
373 symbols 1,129 edges 22 files 97 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CI Coverage Crates.io pypi versions

PowerBoxes

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 area

Box convert

Here it's torchvision vs powerboxes

Box convert

Box IoU matrix

Torchvision vs numpy vs powerboxes

Box IoU

NMS

Torchvision vs powerboxes vs lsnms vs numpy

Large image (10000x10000 pixels)

Box NMS

Normal image (1000x1000 pixels)

Box NMS

Core symbols most depended-on inside this repo

min
called by 57
powerboxesrs/src/utils.rs
max
called by 40
powerboxesrs/src/utils.rs
array_to_numpy
called by 25
bindings/src/utils.rs
preprocess_boxes
called by 21
bindings/src/utils.rs
points
called by 18
powerboxesrs/src/rotation.rs
row5
called by 17
powerboxesrs/src/utils.rs
row4
called by 16
powerboxesrs/src/utils.rs
minimal_bounding_rect
called by 16
powerboxesrs/src/rotation.rs

Shape

Function 335
Method 29
Class 8
Enum 1

Languages

Rust57%
Python43%

Modules by API surface

bindings/tests/test_dtypes.py54 symbols
powerboxesrs/src/boxes.rs34 symbols
bindings/tests/test_speed.py28 symbols
powerboxesrs/src/rotation.rs27 symbols
bindings/src/lib.rs25 symbols
bindings/python/powerboxes/__init__.py25 symbols
bindings/tests/test_correctness.py24 symbols
powerboxesrs/src/nms.rs23 symbols
powerboxesrs/src/draw.rs22 symbols
bindings/tests/test_draw.py18 symbols
powerboxesrs/src/iou.rs15 symbols
powerboxesrs/benches/bench_iou.rs11 symbols

For agents

$ claude mcp add powerboxes \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact