LineZone, LineZoneAnnotator documentation improvements

This commit is contained in:
SkalskiP committed 2024-02-12 13:43:58 +01:00
1 parent 2e898f137e
commit ba81a09b2c
6 files changed
+50 -14

No files matched your search

+10 -2
View File
@@ -2,6 +2,14 @@
comments: true
---
# LineZone
<div class="md-typeset">
<h2>LineZone</h2>
</div>
:::supervision.detection.line_counter.LineZone
:::supervision.detection.line_zone.LineZone
<div class="md-typeset">
<h2>LineZoneAnnotator</h2>
</div>
:::supervision.detection.line_zone.LineZoneAnnotator
+3 -1
View File
@@ -2,7 +2,9 @@
comments: true
---
# PolygonZone
<div class="md-typeset">
<h2>PolygonZone</h2>
</div>
:::supervision.detection.tools.polygon_zone.PolygonZone
-1
View File
@@ -1,6 +1,5 @@
---
comments: true
status: new
---
# Detection Smoother
+1 -1
View File
@@ -35,7 +35,7 @@ from supervision.dataset.core import (
)
from supervision.detection.annotate import BoxAnnotator
from supervision.detection.core import Detections
from supervision.detection.line_counter import LineZone, LineZoneAnnotator
from supervision.detection.line_zone import LineZone, LineZoneAnnotator
from supervision.detection.tools.csv_sink import CSVSink
from supervision.detection.tools.inference_slicer import InferenceSlicer
from supervision.detection.tools.polygon_zone import PolygonZone, PolygonZoneAnnotator
@@ -14,6 +14,12 @@ class LineZone:
This class is responsible for counting the number of objects that cross a
predefined line.
<video controls>
<source
src="https://media.roboflow.com/supervision/cookbooks/count-objects-crossing-the-line-result-1280x720.mp4"
type="video/mp4">
</video>
!!! warning
LineZone uses the `tracker_id`. Read
@@ -25,7 +31,28 @@ class LineZone:
to inside.
out_count (int): The number of objects that have crossed the line from inside
to outside.
"""
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:
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
```
""" # noqa: E501 // docs
def __init__(
self,
+8 -8
View File
@@ -28,7 +28,7 @@ class VideoInfo:
```python
import supervision as sv
video_info = sv.VideoInfo.from_video_path(video_path='video.mp4')
video_info = sv.VideoInfo.from_video_path(video_path=<SOURCE_VIDEO_FILE>)
video_info
# VideoInfo(width=3840, height=2160, fps=25, total_frames=538)
@@ -75,14 +75,14 @@ class VideoSink:
```python
import supervision as sv
video_info = sv.VideoInfo.from_video_path('source.mp4')
frames_generator = sv.get_video_frames_generator('source.mp4')
video_info = sv.VideoInfo.from_video_path(<SOURCE_VIDEO_PATH>)
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)
with sv.VideoSink(target_path='target.mp4', video_info=video_info) as sink:
with sv.VideoSink(target_path=<TARGET_VIDEO_PATH>, video_info=video_info) as sink:
for frame in frames_generator:
sink.write_frame(frame=frame)
```
"""
""" # noqa: E501 // docs
def __init__(self, target_path: str, video_info: VideoInfo, codec: str = "mp4v"):
self.target_path = target_path
@@ -147,7 +147,7 @@ def get_video_frames_generator(
```python
import supervision as sv
for frame in sv.get_video_frames_generator(source_path='source_video.mp4'):
for frame in sv.get_video_frames_generator(source_path=<SOURCE_VIDEO_PATH>):
...
```
"""
@@ -191,8 +191,8 @@ def process_video(
...
process_video(
source_path='...',
target_path='...',
source_path=<SOURCE_VIDEO_PATH>,
target_path=<TARGET_VIDEO_PATH>,
callback=callback
)
```