generated from roboflow/template-python
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
Q2.2024Tasks planned for execution in Q2 2024.Tasks planned for execution in Q2 2024.api:polygonzonePolygonZone APIPolygonZone APIenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Description
Currently, the initialization of sv.PolygonZone requires passing frame_resolution_wh
in the constructor. Upon further reflection, this seems totally unnecessary.
-
Change the
self.mask
initialization located in the constructor. Instead of basing the shape of the mask onframe_resolution_wh
, calculate thex_max
andy_max
of ourpolygon
and create a mask of a size sufficient for thepolygon
to fit on it.x_max, y_max = np.max(polygon, axis=0) self.mask = polygon_to_mask( polygon=polygon, resolution_wh=(x_max + 1, y_max + 1) )
-
Print an appropriate deprecation warning whenever someone sets the value of
frame_resolution_wh
, notifying thatframe_resolution_wh
is no longer required and will be dropped in versionsupervision-0.24.0
. -
Drop
frame_resolution_wh
from docs.
API
Example usage after making the changes.
import numpy as np
import supervision as sv
from ultralytics import YOLO
from supervision.assets import download_assets, VideoAssets
download_assets(VideoAssets.VEHICLES)
polygon = np.array([[1252, 787], [2298, 803], [5039, 2159], [-550, 2159]])
zone = sv.PolygonZone(polygon=polygon)
model = YOLO("yolov8x.pt")
color = sv.Color.ROBOFLOW
color_annotator = sv.ColorAnnotator(color=color)
def callback(scene: np.ndarray, index: int) -> np.ndarray:
result = model(scene)[0]
detections = sv.Detections.from_ultralytics(result)
detections_in_zone = detections[zone.trigger(detections=detections)]
annotated_frame = scene.copy()
annotated_frame = sv.draw_polygon(scene, polygon=polygon, color=color)
annotated_frame = color_annotator.annotate(scene, detections=detections_in_zone)
return annotated_frame
sv.process_video(
source_path="vehicles.mp4",
target_path="vehicles-result.mp4",
callback=callback
)
Additional
- Note: Please share a Google Colab with minimal code to test the new feature. We know it's additional work, but it will speed up the review process. The reviewer must test each change. Setting up a local environment to do this is time-consuming. Please ensure that Google Colab can be accessed without any issues (make it public). Thank you! 🙏🏻
Metadata
Metadata
Assignees
Labels
Q2.2024Tasks planned for execution in Q2 2024.Tasks planned for execution in Q2 2024.api:polygonzonePolygonZone APIPolygonZone APIenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Type
Projects
Status
Done