Preserve original points in `resample_segments` (#18051)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
pull/17719/head^2
Mohammed Yasin 1 week ago committed by GitHub
parent 9be4b2ca04
commit 1f5646634d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      ultralytics/utils/ops.py

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

Loading…
Cancel
Save