Skip to content

Commit

Permalink
Update utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikdava authored Dec 3, 2024
1 parent bf5a92c commit 80380d1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions supervision/detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,22 +762,22 @@ def scale_boxes(
return np.concatenate((centers - new_sizes / 2, centers + new_sizes / 2), axis=1)


def resolve_letterbox(
xyxy: npt.NDArray[np.float64],
letterbox_wh: Tuple[int, int],
resolution_wh: Tuple[int, int],
) -> npt.NDArray[np.float64]:

def resolve_letterbox(xyxy: npt.NDArray[np.float64],
letterbox_wh: Tuple[int, int],
resolution_wh: Tuple[int, int]) -> npt.NDArray[np.float64]:
"""
Resolves the bounding box coordinates from letterbox format to the required resolution.
Resolves the bounding box coordinates from letterbox format
to the required resolution.
Args:
xyxy (npt.NDArray[np.float64]): An array of shape `(n, 4)` containing the
bounding boxes coordinates in format `[x1, y1, x2, y2]`
letterbox_wh (Tuple[int, int]): The target resolution as `(width, height)`.
resolution_wh (Tuple[int, int]): The target resolution as `(width, height)`.
Returns:
Detections: A new Detections object with the bounding box coordinates resolved to the
target resolution.
Detections: A new Detections object with the bounding box coordinates resolved
to the target resolution.
"""

input_w, input_h = resolution_wh
Expand All @@ -794,7 +794,7 @@ def resolve_letterbox(

scale = input_w / width_new

padding_top = (letterbox_h - height_new) // 2
padding_top = (letterbox_h - height_new) // 2
padding_left = (letterbox_w - width_new) // 2

boxes = xyxy.copy()
Expand Down

0 comments on commit 80380d1

Please sign in to comment.