From 1f5646634d3ec00aa85bc53397d552a2d19017a3 Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Fri, 6 Dec 2024 05:21:54 +0800 Subject: [PATCH] Preserve original points in `resample_segments` (#18051) Co-authored-by: Glenn Jocher --- ultralytics/utils/ops.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ultralytics/utils/ops.py b/ultralytics/utils/ops.py index c6ebaf65..50c861de 100644 --- a/ultralytics/utils/ops.py +++ b/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