Fix missing labels when all segment points are out of bounds (#17810)

Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
This commit is contained in:
Mohammed Yasin 2024-11-27 01:23:41 +08:00 committed by GitHub
parent d8c43874ae
commit d8a339d370
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)