Preserve original points in resample_segments (#18051)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Mohammed Yasin 2024-12-06 05:21:54 +08:00 committed by GitHub
parent 9be4b2ca04
commit 1f5646634d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -625,8 +625,9 @@ def resample_segments(segments, n=1000):
"""
for i, s in enumerate(segments):
s = np.concatenate((s, s[0:1, :]), axis=0)
x = np.linspace(0, len(s) - 1, n)
x = np.linspace(0, len(s) - 1, n - len(s) if len(s) < n else n)
xp = np.arange(len(s))
x = np.insert(x, np.searchsorted(x, xp), xp) if len(s) < n else x
segments[i] = (
np.concatenate([np.interp(x, xp, s[:, i]) for i in range(2)], dtype=np.float32).reshape(2, -1).T
) # segment xy