Revert segment2box and clip segments (#18294)
This commit is contained in:
parent
31aaf0e057
commit
f0d3b167fb
1 changed files with 7 additions and 2 deletions
|
|
@ -75,8 +75,13 @@ def segment2box(segment, width=640, height=640):
|
||||||
(np.ndarray): the minimum and maximum x and y values of the segment.
|
(np.ndarray): the minimum and maximum x and y values of the segment.
|
||||||
"""
|
"""
|
||||||
x, y = segment.T # segment xy
|
x, y = segment.T # segment xy
|
||||||
x = x.clip(0, width)
|
# any 3 out of 4 sides are outside the image, clip coordinates first, https://github.com/ultralytics/ultralytics/pull/18294
|
||||||
y = y.clip(0, height)
|
if np.array([x.min() < 0, y.min() < 0, x.max() > width, y.max() > height]).sum() >= 3:
|
||||||
|
x = x.clip(0, width)
|
||||||
|
y = y.clip(0, height)
|
||||||
|
inside = (x >= 0) & (y >= 0) & (x <= width) & (y <= height)
|
||||||
|
x = x[inside]
|
||||||
|
y = y[inside]
|
||||||
return (
|
return (
|
||||||
np.array([x.min(), y.min(), x.max(), y.max()], dtype=segment.dtype)
|
np.array([x.min(), y.min(), x.max(), y.max()], dtype=segment.dtype)
|
||||||
if any(x)
|
if any(x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue