From d8a339d370b96936cc916e343b6f845b1fca5576 Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Wed, 27 Nov 2024 01:23:41 +0800 Subject: [PATCH] Fix missing labels when all segment points are out of bounds (#17810) Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com> --- ultralytics/utils/ops.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ultralytics/utils/ops.py b/ultralytics/utils/ops.py index 25e83c61c3..ac53546ed1 100644 --- a/ultralytics/utils/ops.py +++ b/ultralytics/utils/ops.py @@ -75,9 +75,8 @@ def segment2box(segment, width=640, height=640): (np.ndarray): the minimum and maximum x and y values of the segment. """ x, y = segment.T # segment xy - inside = (x >= 0) & (y >= 0) & (x <= width) & (y <= height) - x = x[inside] - y = y[inside] + x = x.clip(0, width) + y = y.clip(0, height) return ( np.array([x.min(), y.min(), x.max(), y.max()], dtype=segment.dtype) if any(x)