擅长:python、mysql、java
<p>可以通过以下代码平滑路径:</p>
<pre><code>from scipy.ndimage import gaussian_filter1d
import numpy as np
a=np.array([[78.03881018900006, 30.315651467000066],
[78.044901609000078, 30.31512798600005],
[78.04927981700007, 30.312510579000048],
[78.050041244000056, 30.301755415000059],
[78.072646124000073, 30.281720353000082],
[78.07902308000007, 30.273344651000059]])
x, y = a.T
t = np.linspace(0, 1, len(x))
t2 = np.linspace(0, 1, 100)
x2 = np.interp(t2, t, x)
y2 = np.interp(t2, t, y)
sigma = 10
x3 = gaussian_filter1d(x2, sigma)
y3 = gaussian_filter1d(y2, sigma)
x4 = np.interp(t, t2, x3)
y4 = np.interp(t, t2, y3)
plot(x, y, "o-", lw=2)
plot(x3, y3, "r", lw=2)
plot(x4, y4, "o", lw=2)
</code></pre>
<p>结果是:蓝色点是原始数据,红色曲线是包含多个点的平滑曲线,如果您想要与原始数据相同的点计数,您可以从红色曲线采样并得到绿色点。</p>
<p>您可以设置<code>sigma</code>来更改<code>gaussian_filter1d()</code>的平滑级别。</p>
<p><img src="https://i.stack.imgur.com/OCaAf.png" alt="enter image description here"/></p>