From 0c67942d32a650eee0ae13ec123587256ace3903 Mon Sep 17 00:00:00 2001 From: Lourdhu Raju <109408033+Lourdhu02@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:03:46 +0530 Subject: [PATCH] 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 --- .../detection/tools/polygon_zone.py | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/supervision/detection/tools/polygon_zone.py b/src/supervision/detection/tools/polygon_zone.py index 58e979f9..acb95522 100644 --- a/src/supervision/detection/tools/polygon_zone.py +++ b/src/supervision/detection/tools/polygon_zone.py @@ -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("") - 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) ``` """