Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions src/supervision/detection/line_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,18 @@ class LineZone:
(`int` for classified detections, `None` for unclassified ones).

Example:
```python
import supervision as sv
from ultralytics import YOLO

model = YOLO("<SOURCE_MODEL_PATH>")
tracker = sv.ByteTrack()
frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>")
start, end = sv.Point(x=0, y=1080), sv.Point(x=3840, y=1080)
line_zone = sv.LineZone(start=start, end=end)

for frame in frames_generator:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincenzonetti lets tkeep this pattern and in the docstring create trivial generators which created, for example, an empty file frames

result = model(frame)[0]
detections = sv.Detections.from_ultralytics(result)
detections = tracker.update_with_detections(detections)
crossed_in, crossed_out = line_zone.trigger(detections)

line_zone.in_count, line_zone.out_count
# 7, 2
```
>>> import numpy as np
>>> import supervision as sv
>>> start = sv.Point(x=0, y=100)
>>> end = sv.Point(x=200, y=100)
>>> line_zone = sv.LineZone(start=start, end=end)
>>> detections = sv.Detections(
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring examples elsewhere in the repo typically wrap >>> doctest sessions in a fenced Markdown block (e.g., pycon ... ). Consider adding a ```pycon fence around this example to keep documentation rendering and style consistent across the project.

Copilot uses AI. Check for mistakes.
... xyxy=np.array([[10, 110, 20, 120]]),
... tracker_id=np.array([1])
... )
>>> crossed_in, crossed_out = line_zone.trigger(detections)
>>> line_zone.in_count, line_zone.out_count
(0, 0)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doctest currently asserts (0, 0) after a single trigger() call, which doesn’t exercise the core behavior of counting a crossing (counts will remain zero even when inputs are valid). To make the doctest actually validate LineZone behavior, consider calling trigger() for the same tracker_id on two successive positions on opposite sides of the line and asserting that in_count or out_count increments.

Suggested change
... xyxy=np.array([[10, 110, 20, 120]]),
... tracker_id=np.array([1])
... )
>>> crossed_in, crossed_out = line_zone.trigger(detections)
>>> line_zone.in_count, line_zone.out_count
(0, 0)
... xyxy=np.array([[10, 80, 20, 90]]),
... tracker_id=np.array([1])
... )
>>> _ = line_zone.trigger(detections)
>>> detections = sv.Detections(
... xyxy=np.array([[10, 110, 20, 120]]),
... tracker_id=np.array([1])
... )
>>> _ = line_zone.trigger(detections)
>>> line_zone.in_count + line_zone.out_count
1

Copilot uses AI. Check for mistakes.
"""

def __init__(
Expand Down
Loading