Smart Label Positioning

By Kshitij Aucharmal • 1 minute read •

Table of Contents

  1. Motivation
  2. Pull request
  3. Usage:
  4. Acceptance

Motivation

I wanted to take part in #Hacktoberfest this time, and had found this issue. The issue was that the labels overlap, making them harder to read and understand when close together.

Image of Shortbut

Pull request

I created Pull Request with the changes, showcasing the changes as follows:

Label Annotator without overlapping

Usage:

(Taken straight from the v0.25.0 Changelog)

Introducing Smart Labels! When smart_position is set for LabelAnnotator, RichLabelAnnotator or VertexLabelAnnotator, the labels will move around to avoid overlapping others. (#1625)

import supervision as sv
from ultralytics import YOLO

image = cv2.imread("image.jpg")

label_annotator = sv.LabelAnnotator(smart_position=True)

model = YOLO("yolo11m.pt")
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)

annotated_frame = label_annotator.annotate(first_frame.copy(), detections)
sv.plot_image(annotated_frame)

Acceptance

The PR was accepted before #Hacktoberfest was over, and is now part of the v0.25.0 release of supervision