supervision

0.27.0.post2 · active · verified Sun Apr 12

Supervision is a Python library providing a set of easy-to-use utilities for computer vision projects. It simplifies common tasks such as object detection, segmentation, pose estimation, and tracking by offering robust data structures, annotators, and metrics. The library is actively maintained with frequent releases, currently at version 0.27.0.post2.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create dummy image data and detections, then use `sv.BoxAnnotator` to visualize them. This minimal example does not require an external deep learning model, only `numpy` and `opencv-python` (which are often installed automatically with `supervision[all]` or manually needed for CV tasks).

import supervision as sv
import numpy as np
import cv2

# Simulate an image (e.g., loaded from file or camera feed)
image_height, image_width = 720, 1280
image = np.zeros((image_height, image_width, 3), dtype=np.uint8)
cv2.rectangle(image, (100, 100), (300, 300), (255, 255, 255), -1)
cv2.putText(image, "Dummy Image", (500, 360), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)

# Simulate object detections (e.g., from a YOLO model)
detections = sv.Detections(
    xyxy=np.array([[150, 150, 250, 250], [500, 500, 600, 600]]),
    confidence=np.array([0.9, 0.8]),
    class_id=np.array([0, 1]),
    tracker_id=np.array([1, 2]),
    class_name=np.array(['person', 'car'])
)

# Create an annotator (e.g., for bounding boxes)
box_annotator = sv.BoxAnnotator(
    thickness=2, 
    text_thickness=2, 
    text_scale=1
)

# Annotate the image with the simulated detections
annotated_image = box_annotator.annotate(
    scene=image.copy(),
    detections=detections,
    labels=[f"Class {class_id} {confidence:.2f}" for class_id, confidence in zip(detections.class_id, detections.confidence)]
)

# In a real application, you would display or save 'annotated_image'
# For this quickstart, we'll print confirmation.
print(f"Annotated image shape: {annotated_image.shape}")
assert annotated_image.shape == image.shape
print("Supervision quickstart example ran successfully.")
# Example of saving the image:
# cv2.imwrite("annotated_output.jpg", annotated_image)

view raw JSON →