This module provides utility functions for processing and post-processing image data, particularly for object detection tasks using YOLO-like models. It includes functions for bounding box coordinate conversion, non-maximum suppression (NMS), image preprocessing, and detection result post-processing.
The module contains helper functions that are commonly used in the pipeline of object detection models, from preparing input images to interpreting and refining the model's output.
"""
importmath
fromtypingimportList
@@ -7,15 +13,23 @@ from PIL import Image
def_yolo_xywh2xyxy(x:np.ndarray)->np.ndarray:
"""
Copied from yolov8.
Convert bounding box coordinates from (x, y, width, height) format to (x1, y1, x2, y2) format.
This function is adapted from YOLOv8 and transforms the center-based representation
to a corner-based representation of bounding boxes.
:param x: Input bounding box coordinates in (x, y, width, height) format.
:type x: np.ndarray
Convert bounding box coordinates from (x, y, width, height) format to (x1, y1, x2, y2) format where (x1, y1) is the
top-left corner and (x2, y2) is the bottom-right corner.
:return: Bounding box coordinates in (x1, y1, x2, y2) format.
:rtype: np.ndarray
Args:
x (np.ndarray) or (torch.Tensor): The input bounding box coordinates in (x, y, width, height) format.
Returns:
y (np.ndarray) or (torch.Tensor): The bounding box coordinates in (x1, y1, x2, y2) format.