Skip to content
Open
Changes from all commits
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
50 changes: 32 additions & 18 deletions src/supervision/detection/line_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,38 @@ 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
```pycon
>>> import numpy as np
>>> import supervision as sv
>>> def frames_generator():
... yield np.zeros((1080, 1920, 3), dtype=np.uint8)
...
>>> start = sv.Point(x=0, y=100)
>>> end = sv.Point(x=200, y=100)
>>> line_zone = sv.LineZone(start=start, end=end)
>>> for frame in frames_generator():
... detections = sv.Detections(
... xyxy=np.array([[10, 110, 20, 150]]),
... tracker_id=np.array([1])
... )
... crossed_in, crossed_out = line_zone.trigger(
... detections
... )
...
>>> line_zone.in_count, line_zone.out_count
(0, 0)
>>> for frame in frames_generator():
... detections = sv.Detections(
... xyxy=np.array([[10, 50, 20, 90]]),
... tracker_id=np.array([1])
... )
... crossed_in, crossed_out = line_zone.trigger(
... detections
... )
...
>>> line_zone.in_count, line_zone.out_count
(1, 0)

```
"""

Expand Down
Loading