diff --git a/src/supervision/assets/downloader.py b/src/supervision/assets/downloader.py index 1a6ff5bc..d507b643 100644 --- a/src/supervision/assets/downloader.py +++ b/src/supervision/assets/downloader.py @@ -18,8 +18,8 @@ def is_md5_hash_matching(filename: str, original_md5_hash: str) -> bool: Note: MD5 is used here for file integrity checking (detecting corruption), not for cryptographic security purposes. - Parameters: - filename: The path to the file to be checked as a string. + Args: + filename: The path to the file to be checked. original_md5_hash: The original MD5 hash to compare against. Returns: @@ -39,9 +39,8 @@ def download_assets(asset_name: VideoAssets | str) -> str: """ Download a specified asset if it doesn't already exist or is corrupted. - Parameters: - asset_name: The name or type of the asset to be - downloaded. + Args: + asset_name: The name or type of the asset to be downloaded. Returns: The filename of the downloaded asset. diff --git a/src/supervision/detection/core.py b/src/supervision/detection/core.py index f3305fc1..56a20358 100644 --- a/src/supervision/detection/core.py +++ b/src/supervision/detection/core.py @@ -1722,11 +1722,11 @@ class Detections: [ncnn](https://github.com/Tencent/ncnn) inference result. Supports object detection models. - Arguments: - ncnn_results (dict): The output Results instance from ncnn. + Args: + ncnn_results: The output Results instance from ncnn. Returns: - Detections: A new Detections object. + A new Detections object. Example: ```python diff --git a/src/supervision/detection/utils/converters.py b/src/supervision/detection/utils/converters.py index f22f30e6..ad051293 100644 --- a/src/supervision/detection/utils/converters.py +++ b/src/supervision/detection/utils/converters.py @@ -183,13 +183,12 @@ def mask_to_xyxy(masks: np.ndarray) -> np.ndarray: """ Converts a 3D `np.array` of 2D bool masks into a 2D `np.array` of bounding boxes. - Parameters: - masks (np.ndarray): A 3D `np.array` of shape `(N, W, H)` - containing 2D bool masks + Args: + masks: A 3D `np.array` of shape `(N, W, H)` containing 2D bool masks. Returns: - np.ndarray: A 2D `np.array` of shape `(N, 4)` containing the bounding boxes - `(x_min, y_min, x_max, y_max)` for each mask + A 2D `np.array` of shape `(N, 4)` containing the bounding boxes + `(x_min, y_min, x_max, y_max)` for each mask. """ n = masks.shape[0] xyxy = np.zeros((n, 4), dtype=int) @@ -209,15 +208,15 @@ def xyxy_to_mask(boxes: np.ndarray, resolution_wh: tuple[int, int]) -> np.ndarra """ Converts a 2D `np.ndarray` of bounding boxes into a 3D `np.ndarray` of bool masks. - Parameters: - boxes (np.ndarray): A 2D `np.ndarray` of shape `(N, 4)` - containing bounding boxes `(x_min, y_min, x_max, y_max)` - resolution_wh (Tuple[int, int]): A tuple `(width, height)` specifying - the resolution of the output masks + Args: + boxes: A 2D `np.ndarray` of shape `(N, 4)` containing bounding boxes + `(x_min, y_min, x_max, y_max)`. + resolution_wh: A tuple `(width, height)` specifying the resolution of + the output masks. Returns: - np.ndarray: A 3D `np.ndarray` of shape `(N, height, width)` - containing 2D bool masks for each bounding box + A 3D `np.ndarray` of shape `(N, height, width)` containing 2D bool masks + for each bounding box. Examples: >>> import numpy as np @@ -263,15 +262,14 @@ def mask_to_polygons(mask: np.ndarray) -> list[np.ndarray]: """ Converts a binary mask to a list of polygons. - Parameters: - mask (np.ndarray): A binary mask represented as a 2D NumPy array of - shape `(H, W)`, where H and W are the height and width of - the mask, respectively. + Args: + mask: A binary mask represented as a 2D NumPy array of shape `(H, W)`, + where H and W are the height and width of the mask, respectively. Returns: - List[np.ndarray]: A list of polygons, where each polygon is represented by a - NumPy array of shape `(N, 2)`, containing the `x`, `y` coordinates - of the points. Polygons with fewer points than `MIN_POLYGON_POINT_COUNT = 3` + A list of polygons, where each polygon is represented by a NumPy array + of shape `(N, 2)`, containing the `x`, `y` coordinates of the + points. Polygons with fewer points than `MIN_POLYGON_POINT_COUNT = 3` are excluded from the output. """ @@ -289,12 +287,12 @@ def polygon_to_xyxy(polygon: np.ndarray) -> np.ndarray: """ Converts a polygon represented by a NumPy array into a bounding box. - Parameters: - polygon (np.ndarray): A polygon represented by a NumPy array of shape `(N, 2)`, + Args: + polygon: A polygon represented by a NumPy array of shape `(N, 2)`, containing the `x`, `y` coordinates of the points. Returns: - np.ndarray: A 1D NumPy array containing the bounding box + A 1D NumPy array containing the bounding box `(x_min, y_min, x_max, y_max)` of the input polygon. """ x_min, y_min = np.min(polygon, axis=0) diff --git a/src/supervision/draw/utils.py b/src/supervision/draw/utils.py index 979e1cb6..a6dca7b7 100644 --- a/src/supervision/draw/utils.py +++ b/src/supervision/draw/utils.py @@ -21,15 +21,15 @@ def draw_line( """ Draws a line on a given scene. - Parameters: - scene (np.ndarray): The scene on which the line will be drawn - start (Point): The starting point of the line - end (Point): The end point of the line - color (Color): The color of the line, defaults to Color.ROBOFLOW - thickness (int): The thickness of the line + Args: + scene: The scene on which the line will be drawn + start: The starting point of the line + end: The end point of the line + color: The color of the line, defaults to Color.ROBOFLOW + thickness: The thickness of the line Returns: - np.ndarray: The scene with the line drawn on it + The scene with the line drawn on it """ cv2.line( scene, @@ -50,14 +50,14 @@ def draw_rectangle( """ Draws a rectangle on an image. - Parameters: - scene (np.ndarray): The scene on which the rectangle will be drawn - rect (Rect): The rectangle to be drawn - color (Color): The color of the rectangle - thickness (int): The thickness of the rectangle border + Args: + scene: The scene on which the rectangle will be drawn + rect: The rectangle to be drawn + color: The color of the rectangle + thickness: The thickness of the rectangle border Returns: - np.ndarray: The scene with the rectangle drawn on it + The scene with the rectangle drawn on it """ cv2.rectangle( scene, @@ -78,14 +78,14 @@ def draw_filled_rectangle( """ Draws a filled rectangle on an image. - Parameters: - scene (np.ndarray): The scene on which the rectangle will be drawn - rect (Rect): The rectangle to be drawn - color (Color): The color of the rectangle - opacity (float): The opacity of rectangle when drawn on the scene. + Args: + scene: The scene on which the rectangle will be drawn + rect: The rectangle to be drawn + color: The color of the rectangle + opacity: The opacity of rectangle when drawn on the scene. Returns: - np.ndarray: The scene with the rectangle drawn on it + The scene with the rectangle drawn on it """ if opacity == 1: cv2.rectangle( @@ -120,14 +120,14 @@ def draw_rounded_rectangle( """ Draws a rounded rectangle on an image. - Parameters: - scene (np.ndarray): The image on which the rounded rectangle will be drawn. - rect (Rect): The rectangle to be drawn. - color (Color): The color of the rounded rectangle. - border_radius (int): The radius of the corner rounding. + Args: + scene: The image on which the rounded rectangle will be drawn. + rect: The rectangle to be drawn. + color: The color of the rounded rectangle. + border_radius: The radius of the corner rounding. Returns: - np.ndarray: The image with the rounded rectangle drawn on it. + The image with the rounded rectangle drawn on it. """ x1, y1, x2, y2 = rect.as_xyxy_int_tuple() width, height = x2 - x1, y2 - y1 @@ -171,14 +171,14 @@ def draw_polygon( ) -> npt.NDArray[np.uint8]: """Draw a polygon on a scene. - Parameters: - scene (np.ndarray): The scene to draw the polygon on. - polygon (np.ndarray): The polygon to be drawn, given as a list of vertices. - color (Color): The color of the polygon. Defaults to Color.ROBOFLOW. - thickness (int): The thickness of the polygon lines, by default 2. + Args: + scene: The scene to draw the polygon on. + polygon: The polygon to be drawn, given as a list of vertices. + color: The color of the polygon. Defaults to Color.ROBOFLOW. + thickness: The thickness of the polygon lines, by default 2. Returns: - np.ndarray: The scene with the polygon drawn on it. + The scene with the polygon drawn on it. """ cv2.polylines( scene, [polygon], isClosed=True, color=color.as_bgr(), thickness=thickness @@ -194,14 +194,14 @@ def draw_filled_polygon( ) -> npt.NDArray[np.uint8]: """Draw a filled polygon on a scene. - Parameters: - scene (np.ndarray): The scene to draw the polygon on. - polygon (np.ndarray): The polygon to be drawn, given as a list of vertices. - color (Color): The color of the polygon. Defaults to Color.ROBOFLOW. - opacity (float): The opacity of polygon when drawn on the scene. + Args: + scene: The scene to draw the polygon on. + polygon: The polygon to be drawn, given as a list of vertices. + color: The color of the polygon. Defaults to Color.ROBOFLOW. + opacity: The opacity of polygon when drawn on the scene. Returns: - np.ndarray: The scene with the polygon drawn on it. + The scene with the polygon drawn on it. """ if opacity == 1: cv2.fillPoly(scene, [polygon], color=color.as_bgr()) diff --git a/src/supervision/geometry/utils.py b/src/supervision/geometry/utils.py index 1234dd2e..f51e4577 100644 --- a/src/supervision/geometry/utils.py +++ b/src/supervision/geometry/utils.py @@ -9,13 +9,13 @@ def get_polygon_center(polygon: npt.NDArray[np.float64]) -> Point: Calculate the center of a polygon. The center is calculated as the center of the solid figure formed by the points of the polygon - Parameters: - polygon (np.ndarray): A 2-dimensional numpy ndarray representing the - vertices of the polygon. + Args: + polygon: A 2-dimensional numpy ndarray representing the vertices of the + polygon. Returns: - Point: The center of the polygon, represented as a - Point object with x and y attributes. + The center of the polygon, represented as a Point object with x and y + attributes. Raises: ValueError: If the polygon has no vertices.