Skip to main content

A lightweight and easy bounding box manipulation library with Pascal VOC, COCO, and YOLO format conversions.

Project description

Easy Bbox

Package version License Coverage Documentation

Easy Bbox is a Python package designed to simplify bounding box operations. It provides a comprehensive set of tools for manipulating bounding boxes in various coordinate formats, including Pascal VOC, COCO, YOLO and Albumentations. The package supports transformations, geometric operations, and conversions, making it a versatile tool for computer vision tasks.

Features

  • Pydantic model: Bbox objects are Pydantic models.
  • Multiple Coordinate Formats: Supports Pascal VOC, COCO, YOLO and Albumentation formats.
  • Transformations: Shift, scale, expand, and pad bounding boxes.
  • Geometric Operations: Calculate intersections, unions, and IoU (Intersection over Union).
  • Conversions: Convert between different coordinate formats.
  • Utility Functions: Includes Non-Maximum Suppression (NMS) for filtering overlapping bounding boxes.

Installation

Easy Bbox is published as a python package and can be pip installed.

pip install easy-bbox

Usage

Creating a Bounding Box

You can create a bounding box using the Bbox class. The bounding box is stored in Pascal VOC format, which is top-left, bottom-right with a top-left origin (PIL coordinate system), but can be instantiated from different formats.

from easy_bbox import Bbox

# All of the following Bbox are equal

# Create a bounding box using top-left and bottom-right coordinates
bbox = Bbox(left=10, top=20, right=30, bottom=40)

# Instantiate from a sequence in Pascal VOC format
bbox = Bbox.from_pascal_voc([10, 20, 30, 40])  
bbox = Bbox.from_tlbr([10, 20, 30, 40])   
bbox = Bbox.from_xyxy([10, 20, 30, 40])  
bbox = Bbox.from_list([10, 20, 30, 40])

# Create a bounding box using top-left and width-height coordinates (COCO format)
bbox = Bbox.from_tlwh((10, 20, 20, 20))
bbox = Bbox.from_coco((10, 20, 20, 20))

# Create a bounding box using center and width-height coordinates
bbox = Bbox.from_cwh((20, 30, 20, 20))

Transformations

Easy Bbox provides several methods for transforming bounding boxes:

bbox_transformations

Conversions

Easy Bbox provides methods for converting between different coordinate formats:

# Convert to Top-Left, Bottom-Right format
tlbr = bbox.to_tlbr() # Same as `.to_pascal_voc()`, `.to_xyxy()`

# Convert to Top-Left, Width-Height format
tlwh = bbox.to_tlwh()   # Same as `.to_coco()`

# Convert to Center, Width-Height format
cwh = bbox.to_cwh()

# Convert to normalized Top-Left, Bottom-Right format
norm_tlbr = bbox.to_norm_tlbr(img_w=100, img_h=100) # Same as `.to_albu(...)`

# Convert to normalized Top-Left, Width-Height format
norm_tlwh = bbox.to_norm_tlwh(img_w=100, img_h=100)

# Convert to normalized Center, Width-Height format
norm_cwh = bbox.to_norm_cwh(img_w=100, img_h=100) # Same as `.to_yolo(...)`

# Convert to polygon format
polygon = bbox.to_polygon()

Utility

Easy Bbox includes utility functions for common tasks:

bbox_utils

from easy_bbox import nms

# Get the minimal englobing bbox
union = bbox1.union(bbox2) # same as bbox1 | bbox2

# Get the intersection
inter = bbox1.intersection(bbox2) # same as bbox1 & bbox2

# Calculate the IoU of two bboxes
iou = bbox1.iou(bbox2)

# Check if two bboxes are overlapping
overlap = bbox1.overlaps(bbox2)

# Check if a bbox contains a point
is_inside = bbox1.contains_point((5, 10))

# Calculate the distance from a point to a bbox
dist = bbox1.distance_to_point((5, 10))

# Perform Non-Maximum Suppression
selected_bboxes = nms(bboxes, scores, iou_threshold=0.5)

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

easy_bbox-1.0.4.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

easy_bbox-1.0.4-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file easy_bbox-1.0.4.tar.gz.

File metadata

  • Download URL: easy_bbox-1.0.4.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for easy_bbox-1.0.4.tar.gz
Algorithm Hash digest
SHA256 909df31de1ac8dd3ab1ebc0ad875b423535ed00a32a3c1fe68e82753412875fd
MD5 fd391d09306a27ecac04b2626e7f6e40
BLAKE2b-256 57a4718328c540c27744ca89b18913d9aa272dc393c860e9b4dd9b439e57f27e

See more details on using hashes here.

File details

Details for the file easy_bbox-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: easy_bbox-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for easy_bbox-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e475b3cf2c07294d110d13a7b39eeb1c556d8e9c9ec4a434e9839defec582c10
MD5 f7b48f669be147fdc7426a3baeb8f561
BLAKE2b-256 af106b640b5ccbb486867c78d4e5ac6c2b3983b0f183b91189da7594147c5796

See more details on using hashes here.

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