Refactor/polygon zone doctest (#2264)
Replaces the static python code block with a pycon doctest using primitive numpy inputs, so the example is now executed and verified by `pytest --doctest-modules`. Removes the external YOLO, ByteTrack, and cv2 dependencies from the example. Follows the same pattern as PR #2207 (LineZone). Part of the documentation-as-tests effort tracked in #2106. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
7d2259669b
commit
0c67942d32
|
|
@ -36,25 +36,20 @@ class PolygonZone:
|
|||
mask: The 2D bool mask for the polygon zone
|
||||
|
||||
Example:
|
||||
```python
|
||||
import supervision as sv
|
||||
from ultralytics import YOLO
|
||||
import numpy as np
|
||||
import cv2
|
||||
```pycon
|
||||
>>> import numpy as np
|
||||
>>> import supervision as sv
|
||||
>>> polygon = np.array([[100, 200], [200, 100], [300, 200], [200, 300]])
|
||||
>>> polygon_zone = sv.PolygonZone(polygon=polygon)
|
||||
>>> detections = sv.Detections(
|
||||
... xyxy=np.array([[180, 100, 220, 200], [400, 400, 450, 500]])
|
||||
... )
|
||||
>>> is_detections_in_zone = polygon_zone.trigger(detections)
|
||||
>>> is_detections_in_zone
|
||||
array([ True, False])
|
||||
>>> polygon_zone.current_count
|
||||
1
|
||||
|
||||
image = cv2.imread("<SOURCE_IMAGE_PATH>")
|
||||
model = YOLO("yolo11s")
|
||||
tracker = sv.ByteTrack()
|
||||
|
||||
polygon = np.array([[100, 200], [200, 100], [300, 200], [200, 300]])
|
||||
polygon_zone = sv.PolygonZone(polygon=polygon)
|
||||
|
||||
result = model.infer(image)[0]
|
||||
detections = sv.Detections.from_ultralytics(result)
|
||||
detections = tracker.update_with_detections(detections)
|
||||
|
||||
is_detections_in_zone = polygon_zone.trigger(detections)
|
||||
print(polygon_zone.current_count)
|
||||
```
|
||||
"""
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue