From b91bc91897f0a331ab4374d4b63e442dbc1de3fa Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Tue, 14 Mar 2023 12:41:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=96=A4=20make=20black=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/detection/polygon_zone.py | 12 ++++++++---- supervision/detection/utils.py | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/supervision/detection/polygon_zone.py b/supervision/detection/polygon_zone.py index 2bb321bb..da60a62c 100644 --- a/supervision/detection/polygon_zone.py +++ b/supervision/detection/polygon_zone.py @@ -1,11 +1,11 @@ -from typing import Optional, Tuple from dataclasses import replace +from typing import Optional, Tuple import cv2 import numpy as np from supervision import Detections -from supervision.detection.utils import generate_2d_mask, clip_boxes +from supervision.detection.utils import clip_boxes, generate_2d_mask from supervision.draw.color import Color from supervision.draw.utils import draw_polygon, draw_text from supervision.geometry.core import Position @@ -25,10 +25,14 @@ class PolygonZone: self.current_count = 0 width, height = frame_resolution_wh - self.mask = generate_2d_mask(polygon=polygon, resolution_wh=(width + 1, height + 1)) + self.mask = generate_2d_mask( + polygon=polygon, resolution_wh=(width + 1, height + 1) + ) def trigger(self, detections: Detections) -> np.ndarray: - clipped_xyxy = clip_boxes(boxes_xyxy=detections.xyxy, frame_resolution_wh=self.frame_resolution_wh) + clipped_xyxy = clip_boxes( + boxes_xyxy=detections.xyxy, frame_resolution_wh=self.frame_resolution_wh + ) clipped_detections = replace(detections, xyxy=clipped_xyxy) clipped_anchors = np.ceil( clipped_detections.get_anchor_coordinates(anchor=self.triggering_position) diff --git a/supervision/detection/utils.py b/supervision/detection/utils.py index f3e1ee08..82b8be3e 100644 --- a/supervision/detection/utils.py +++ b/supervision/detection/utils.py @@ -94,7 +94,9 @@ def non_max_suppression( return keep[sort_index.argsort()] -def clip_boxes(boxes_xyxy: np.ndarray, frame_resolution_wh: Tuple[int, int]) -> np.ndarray: +def clip_boxes( + boxes_xyxy: np.ndarray, frame_resolution_wh: Tuple[int, int] +) -> np.ndarray: """ Clips bounding boxes coordinates to fit within the frame resolution.