【问题标题】:Estimate missing points in a list of points估计点列表中的缺失点
【发布时间】:2020-02-24 20:48:39
【问题描述】:

我通过在视频中检测球的飞行来生成 (x,y) 坐标列表。我遇到的问题是视频中间的几帧无法检测到球,对于这些帧,列表会附加(-1,-1)。 有没有办法为这些点估计球的真实 (x,y) 坐标?

例如跟踪点列表为:

pointList = [(60, 40), (55, 42), (53, 43), (-1, -1), (-1, -1), (-1, -1), (35, 55), (30, 60)]

然后将 3 (-1,-1) 个缺失坐标的估计值返回到环绕点的上下文(保留曲线)。

【问题讨论】:

    标签: python interpolation point


    【解决方案1】:

    如果它是一个球,那么理论上它应该有一条抛物线路径,您可以尝试拟合一条忽略 (-1, -1) 的曲线,然后替换缺失的值。

    有点像……

    import numpy as np
    
    pointList = [(60, 40), (55, 42), (53, 43), (-1, -1), (-1, -1), (-1, -1), (35, 55), (30, 60)]
    
    x, y = list(zip(*[(x, y) for (x, y) in pointList if x>0]))
    
    fit = np.polyfit(x, y, 2)
    polynome = np.poly1d(fit)
    
    # call your polynome for missing data, e.g.
    missing = (55 - i*(55-35)/4 for i in range(3))
    print([(m, polynome(m)) for m in missing])
    

    给...

    [(55.0, 41.971982486554325), (50.0, 44.426515896714186), (45.0, 47.44514924300471)]
    

    【讨论】:

      【解决方案2】:

      您可以使用scipys spline 插入缺失值:

      import numpy as np
      import matplotlib.pyplot as plt
      from scipy.interpolate import splprep, splev
      pointList = [(60, 40), (55, 42), (53, 43),
                   (-1, -1), (-1, -1), (-1, -1), 
                   (35, 55), (30, 60)]
      
      # Remove the missing values
      pointList = np.array(pointList)
      pointList = pointList[pointList[:, 0] != -1, :]
      
      def spline(x, n, k=2):
          tck = splprep(x.T, s=0, k=k)[0]
          u = np.linspace(0.0, 1.0, n)
          return np.column_stack(splev(x=u, tck=tck))
      
      # Interpolate the points with a quadratic spline at 100 points
      pointList_interpolated = spline(pointList, n=100, k=2)
      
      plt.plot(*pointList.T, c='r', ls='', marker='o', zorder=10)
      plt.plot(*pointList_interpolated.T, c='b')
      

      【讨论】:

        【解决方案3】:

        如果相机没有移动——只是球并且你忽略了风,那么轨迹是抛物线的。见:https://en.wikipedia.org/wiki/Trajectory#Uniform_gravity,_neither_drag_nor_wind

        在这种情况下,将二次函数拟合到你知道的点上,你会得到丢失的点。拟合时还将未知区域(点 53,43 和 35, 55)附近边界点的误差设置为 0 或接近 0(无误差,插值权重),这样您的插值将通过这些点。

        有一些用于多项式拟合的库。例如。 numpy.polyfithttps://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.polynomial.polynomial.polyfit.html

        【讨论】:

          猜你喜欢
          • 2012-04-20
          • 1970-01-01
          • 1970-01-01
          • 2012-11-09
          • 1970-01-01
          • 1970-01-01
          • 2012-04-29
          • 1970-01-01
          • 2021-01-30
          相关资源
          最近更新 更多