-
Notifications
You must be signed in to change notification settings - Fork 3.3k
refactor: convert LineZone docstring example to doctest #2207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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: | ||||||||||||||||||||||||||||||||||||
| 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( | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| ... 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, 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 |
There was a problem hiding this comment.
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