Skip to main content

Fast IoU/overlap computations for bounding boxes

Project description

FastBBox

Fast IoU/overlap computations for axis-aligned and oriented bounding boxes, powered by nanobind C++ extensions.

Benchmark

Function Python (ms)    FastBBox (ms)  Speedup
--------------------------------------------------
IoU           1994.19          4.19     475.7x
GIoU          3028.40          5.99     505.8x
DIoU          4104.21          6.21     661.3x
CIoU          6436.51         17.55     366.7x
EIoU          5211.51          7.04     740.5x
NWD           2427.36         13.31     182.4x
OBB          21729.42         31.29     694.5x
--------------------------------------------------
TOTAL        44931.61         85.58     525.1x

Installation

pip install fastbbox

Building from Source

Requires CMake 3.15+ and a C++17 compiler.

git clone https://github.com/gerrylwk/fastbbox
cd fastbbox
pip install .

Usage

Axis-Aligned Bounding Boxes

import numpy as np
from fastbbox import (bbox_overlaps, generalized_iou, distance_iou,
                      complete_iou, efficient_iou, normalized_wasserstein_distance)

# Bounding boxes in [x1, y1, x2, y2] format
boxes = np.array([
    [0, 0, 10, 10],
    [5, 5, 15, 15],
    [20, 20, 30, 30]
], dtype=np.float32)

query_boxes = np.array([
    [0, 0, 10, 10],
    [12, 12, 22, 22]
], dtype=np.float32)

iou = bbox_overlaps(boxes, query_boxes)
giou = generalized_iou(boxes, query_boxes)
diou = distance_iou(boxes, query_boxes)
ciou = complete_iou(boxes, query_boxes)
eiou = efficient_iou(boxes, query_boxes)
nwd = normalized_wasserstein_distance(boxes, query_boxes)

Oriented Bounding Boxes (OBB)

import numpy as np
import math
from fastbbox import bbox_overlaps_obb

# Oriented bounding boxes in [center_x, center_y, width, height, angle_radians] format
obb_boxes = np.array([
    [0, 0, 4, 2, 0],
    [1, 0, 4, 2, math.pi/4],
    [0, 0, 2, 2, math.pi/6],
], dtype=np.float32)

obb_query_boxes = np.array([
    [0, 0, 4, 2, 0],
    [2, 2, 2, 2, 0],
], dtype=np.float32)

obb_iou = bbox_overlaps_obb(obb_boxes, obb_query_boxes)

Features

Axis-Aligned Bounding Box IoU Variants

All variants accept boxes in [x1, y1, x2, y2] top-left-bottom-right format:

Oriented Bounding Box (OBB) IoU

Accepts boxes in [center_x, center_y, width, height, angle_radians] format:

  • Exact calculation for axis-aligned boxes (angle = 0)
  • Approximation-based calculation for rotated boxes using AABB intersection with angle-based scaling
  • Batch processing support

Performance

FastBBox provides significant speedup over pure Python implementations, especially for large numbers of bounding boxes.

Run python benchmark_fastbbox.py to benchmark on your system.

When to Use Each Variant

  • IoU: Standard evaluation, NMS (Non-Maximum Suppression)
  • GIoU: Training loss for non-overlapping boxes
  • DIoU: Object detection training where center distance matters
  • CIoU: Bounding box regression with aspect ratio consistency
  • EIoU: Fast convergence with separate width/height penalties
  • NWD: Tiny object detection
  • OBB IoU: Rotated object detection, text detection, aerial imagery

OBB Implementation Details

The OBB IoU implementation uses different strategies based on box orientations:

  1. Axis-Aligned Boxes (angle = 0): Exact intersection calculation
  2. Rotated Boxes: AABB intersection with scaling factor cos(|angle1|) * cos(|angle2|), minimum 50% retention

For exact rotated box IoU, consider implementing Sutherland-Hodgman clipping or the Separating Axes Theorem (SAT).

Development

Building Locally

pip install build scikit-build-core cmake nanobind
python -m build

Testing Your Build

# Correctness tests (compares fastbbox against Python reference implementations)
python test_fastbbox.py              # Summary output
python test_fastbbox.py --verbose    # Detailed output with values
python test_fastbbox.py -f iou giou  # Test specific functions

# Performance benchmarks
python benchmark_fastbbox.py              # Summary output
python benchmark_fastbbox.py --verbose    # Detailed timing per run
python benchmark_fastbbox.py --size 1000  # Test with 1000 boxes
python benchmark_fastbbox.py --runs 10    # 10 iterations

Test File Options

test_fastbbox.py - Correctness validation:

  • --verbose, -v: Show detailed output with expected/actual values
  • --function, -f: Test specific functions (iou, giou, diou, ciou, eiou, nwd, obb)
  • --tolerance, -t: Tolerance threshold (default: 1e-5)
  • --obb-tolerance: OBB-specific tolerance (default: 1e-3)
  • --size, -s: Number of test boxes (default: 100)

benchmark_fastbbox.py - Performance benchmarks:

  • --verbose, -v: Show individual run times and statistics
  • --function, -f: Benchmark specific functions
  • --size, -s: Number of boxes (default: 500)
  • --runs, -r: Number of iterations (default: 5)

Requirements

  • Python 3.9+
  • NumPy >= 1.19.0

License

MIT License - see LICENSE file for details.

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

fastbbox-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastbbox-0.1.0-cp312-cp312-win_amd64.whl (285.9 kB view details)

Uploaded CPython 3.12Windows x86-64

fastbbox-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (101.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastbbox-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (89.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fastbbox-0.1.0-cp312-cp312-macosx_10_13_x86_64.whl (95.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

fastbbox-0.1.0-cp311-cp311-win_amd64.whl (286.0 kB view details)

Uploaded CPython 3.11Windows x86-64

fastbbox-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (101.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastbbox-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (89.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fastbbox-0.1.0-cp311-cp311-macosx_10_13_x86_64.whl (96.2 kB view details)

Uploaded CPython 3.11macOS 10.13+ x86-64

fastbbox-0.1.0-cp310-cp310-win_amd64.whl (286.3 kB view details)

Uploaded CPython 3.10Windows x86-64

fastbbox-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (102.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastbbox-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (90.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fastbbox-0.1.0-cp310-cp310-macosx_10_13_x86_64.whl (96.5 kB view details)

Uploaded CPython 3.10macOS 10.13+ x86-64

fastbbox-0.1.0-cp39-cp39-win_amd64.whl (288.1 kB view details)

Uploaded CPython 3.9Windows x86-64

fastbbox-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (102.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastbbox-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (90.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

fastbbox-0.1.0-cp39-cp39-macosx_10_13_x86_64.whl (96.6 kB view details)

Uploaded CPython 3.9macOS 10.13+ x86-64

File details

Details for the file fastbbox-0.1.0.tar.gz.

File metadata

  • Download URL: fastbbox-0.1.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastbbox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 142c359152efc0fdded7af48cfcd1cad9a7292d41d3f273c2aeca79f3096815d
MD5 0407a7dc0d04cdeb0ccf29e1455d2013
BLAKE2b-256 6e5c4c0b2fc39959fee77e09eab39c65a9a0880ea016267bdf55e420c5229980

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0.tar.gz:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fastbbox-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 285.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastbbox-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4f3b52e54ad8bfd2f147dfa02c918fc3fac6a19ef3c1bc47a06a403484304f5b
MD5 402b151e5bed793a069d83813251ae93
BLAKE2b-256 ef2e456de1f212fd1d592aa98fc2bf7e90f82b76e4b697d810c2f5b4e3424453

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a7d846cc4e5c4fdf714ce07bb3198a07256197cb284c0cda3952f89dde040855
MD5 6165efd16e0a7571f89a4a085ed8adc0
BLAKE2b-256 4a6e61410aa5ad2941ea66492b28183800065d02147f5257db4d0d0b6b57afa3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5536f8cb691d6623502b6ba4adb2e49d6a755c43628116a764543c70c161e4a1
MD5 a585fa4a41074400b558c972b991e900
BLAKE2b-256 bcd3e746d55b072c62ffae48f3c61cb469fd1df76be8ffc29f0e4c176d0e8cac

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 308037234b89f62c3102b3cb94bc152b31a1328f0abafa053e6ab06948439ba5
MD5 d21a10a105bb42829d4f144ba488b5dc
BLAKE2b-256 f0a27eae1784efc80709eddb660ada49d02766673c607bf91a9fe55ed5897cbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fastbbox-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 286.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastbbox-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5d40f02691babbdc0108a2a2c19a710aeb072474f8c9a22f25a6843c13cafb80
MD5 1912550d4738f677c9f5deb6a9066f84
BLAKE2b-256 ba91f5174ba66a8a17d410d0cfa166489878b41ab99b276b5a79018eecc76699

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bd982f6188d4469dcdc66838515bc7cce73f28bae1fd5d2b8706b15d0960566a
MD5 0af685f5635e557c745b258b0b9e717a
BLAKE2b-256 d0b17116901fdb0fa8e3dda98264b75e3d1f2a398fdb05d448c84e078d0cea58

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5d8b1481e0df3dc3dd56c509dda6d0982590c175819bf2986c3371f3a832b18
MD5 21a98c793002f1ba2afe95f136a62c5b
BLAKE2b-256 6e55e068a7ec43fae28e4a1e9ca53b1ad40bcfa1536f6e895133d716c7fe86f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp311-cp311-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp311-cp311-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b0fc345bceb845e78892b82ca3ba2a335d3b48bf54facd89832ffa0e9743b780
MD5 912b25edfa6e23f2fb9a9b75bcc963ff
BLAKE2b-256 fea5b3de97198c89dda0aa6e0c2915d1ec956fbc99a67841693492f5d2359187

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp311-cp311-macosx_10_13_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: fastbbox-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 286.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastbbox-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 323a21e3d5baa3def0a069a51a620b1e37fb7a62c7a2a8e4b1e6772667cbcccc
MD5 5a7bfe21b3b8a0c5ec955fa48a6bf09b
BLAKE2b-256 c3afd931f919afe9235f836185517df4c1915c6afbd38c7d97316ebc095cbd14

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp310-cp310-win_amd64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 181169a7f270e5a9724d36baa301f3475e9171fb5c76ea11247b2b7e5c4fbecd
MD5 2f0513db43b0767a90452faeebad8db8
BLAKE2b-256 9b589b1ad2427a3633f1a77f514b6ed9aa29d14f80986b0b7cdf1bf25dcd921f

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6fd2002da7323bfce8c09ae2f358096526c9202b8a5d5ff03f1579b05d4b7242
MD5 b314a2b74715b442706d8b0a136bb252
BLAKE2b-256 57adbf84231bee60392d5c0189e494290f23d0e75f6ad530f4a7b3961a50d320

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp310-cp310-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 95ea6abd23be59a794ca155bf4ed938f2c3c83ff370c3f50271fccb36b72df2d
MD5 294a4441856f1a6fa2489f1ca3334b90
BLAKE2b-256 71e0e134ccf9a3a440a22bf61f1447c24fc7c6aa20f1496c02512034d5a5d0bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp310-cp310-macosx_10_13_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: fastbbox-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 288.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastbbox-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9e29b18b778187ac6333a4383027ca3fba233a9830840be5ca76b1313839cecf
MD5 43014a9fd26ad7c958732760940859b6
BLAKE2b-256 a2e29917720eeb0cafd3547ee9e564a640230850196ab3987a21c261b41c4b09

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp39-cp39-win_amd64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d7f07e3a844b95a9dfe0db3b64b9479364acb62142088b52260d90264f5fbf8
MD5 12adf6d5b79a21d9c445bb2e53446e3e
BLAKE2b-256 be6cc60077b6cbd7079ee80e78ab13e626ebaac51ae651abded78be8f990ec5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4ee7d87eab544fe31566c2cd9961298cc8acbc9ddcab49039f3384c5cb67bd0
MD5 b2ce07742655806b15a5f48ad1b05d58
BLAKE2b-256 cff0f82e70e00e67ff5874ec0bd66a8aaa6568d901a603e6b221cbf1ce92c99a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastbbox-0.1.0-cp39-cp39-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for fastbbox-0.1.0-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4edf3d6a50222d71813f2a691f09a5fb6265f30d88582dea53c44f1e1d2e9853
MD5 735e9ecb530bf27a6d9393aec4903afe
BLAKE2b-256 ca4f869b438ccca4c1357231ce84d13c639a7bee56b108952af800bcd167d643

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastbbox-0.1.0-cp39-cp39-macosx_10_13_x86_64.whl:

Publisher: build.yml on gerrylwk/fastbbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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