You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the Supervision issues and found no similar bug report.
Bug
I'm consistently getting an IndexError when using polygon zones:
Traceback (most recent call last):
File "/home/rodrigo/Documents/counter-pog/main.py", line 63, in <module>
main()
File "/home/rodrigo/Documents/counter-pog/main.py", line 53, in main
zone1.trigger(detections=detections)
File "/home/rodrigo/Documents/counter-pog/.venv/lib/python3.10/site-packages/supervision/detection/polygon_zone.py", line 34, in trigger
is_in_zone = self.mask[anchors[:, 1], anchors[:, 0]]
IndexError: index 720 is out of bounds for axis 0 with size 720
Here is the python file in question:
import cv2
from ultralytics import YOLO
import supervision as sv
import numpy as np
VIDEO_PATH = "video.mp4"
def main():
zone1_polygon = np.array([[0, 100], [320, 100], [320, 539], [0, 539]])
video_info = sv.VideoInfo.from_video_path(VIDEO_PATH)
print(video_info)
zone1= sv.PolygonZone(polygon=zone1_polygon, frame_resolution_wh=(video_info.resolution_wh))
zone1_annotator = sv.PolygonZoneAnnotator(zone = zone1, color=sv.Color.white(), thickness=2)
box_annotator = sv.BoxAnnotator(
thickness=2,
text_thickness=1,
text_scale=0.4
)
model = YOLO("yolov8n.pt")
for result in model.track(VIDEO_PATH, show=False, stream=True, agnostic_nms=True):
frame = result.orig_img
detections = sv.Detections.from_yolov8(result)
if result.boxes.id is not None:
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
detections = detections[detections.class_id == 0]
labels = [
f"#{tracker_id}"
for _, confidence, class_id, tracker_id
in detections
]
frame = box_annotator.annotate(
scene=frame,
detections=detections,
labels=labels
)
zone1.trigger(detections=detections)
frame = zone1_annotator.annotate(scene=frame)
cv2.imshow("yolov8", frame)
if (cv2.waitKey(30) == 27):
break
if __name__ == "__main__":
main()
Search before asking
Bug
I'm consistently getting an IndexError when using polygon zones:
Here is the python file in question:
Here is a google colab with the code:
https://colab.research.google.com/drive/1qPiu6dTjNxjpblLRlIUKgsWtN078usEs?usp=sharing
video.mp4
Environment
Minimal Reproducible Example
Execute the python script on the video (both posted above). After a few seconds, the error shows up.
Additional
No response
Are you willing to submit a PR?