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
importnumpyasnp
fromPILimportImage
def_yolo_xywh2xyxy(x:np.ndarray)->np.ndarray:
"""
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
:return: Bounding box coordinates in (x1, y1, x2, y2) format.