"import numpy as np import supervision as sv initiate polygon zone polygon = np.array([…
- User
"import numpy as np import supervision as sv
initiate polygon zone
polygon = np.array([ [540, 985], [1620, 985], [2160, 1920], [1620, 2855], [540, 2855], [0, 1920] ]) video_info = sv.VideoInfo.from_video_path(MARKET_SQUARE_VIDEO_PATH) zone = sv.PolygonZone(polygon=polygon, frame_resolution_wh=video_info.resolution_wh)
extract video frame
generator = sv.get_video_frames_generator(MARKET_SQUARE_VIDEO_PATH) iterator = iter(generator) frame = next(iterator)
detect
results = model(frame, size=1280) detections = sv.Detections.from_yolov5(results) mask = zone.trigger(detections=detections) detections = detections[(detections.class_id == 0) & (detections.confidence > 0.5) & mask]
annotate
box_annotator = sv.BoxAnnotator(thickness=4, text_thickness=4, text_scale=2) frame = box_annotator.annotate(scene=frame, detections=detections) frame = sv.draw_polygon(scene=frame, polygon=polygon, color=sv.Color.red(), thickness=6)
%matplotlib inline
sv.show_frame_in_notebook(frame, (16, 16))"the size=1280 what is the whole resolution? is it 1280x720?
- Assistant
In the context you've provided, the
size=1280parameter is used in themodel(frame, size=1280)call, which appears to be a call to a pre-trained object detection model, possibly YOLOv5 given the later reference toDetections.from_yolov5(results). Thesizeparameter in this case is likely specifying either the width or the longer dimension of the image for inference.In YOLOv5 and similar models, the
sizeparameter does not directly imply the aspect ratio of the image. Instead, it defines the size to which the image will be resized while maintaining its aspect ratio. This is usually done by padding the shorter side with gray pixels after resizing the longer side to the specified size. The actual resolution of the resized image would depend on the original aspect ratio of the image. - User
results = model(frame_rgb, size=900)
can i make this 640x480?
- Assistant
When using the
sizeparameter with the YOLO model, your input parameter typically refers to the size along the longest dimension of the image, and the image will be resized while maintaining its original aspect ratio. This resizing is often not done directly by specifying width and height but by specifying the length of the longest edge. So if you specifysize=900, it means the longest edge of the image will be resized to 900 pixels, with the aspect ratio preserved.