gpt4 book ai didi

python - 如何为缺少数据的移动对象坐标生成插值器?

转载 作者:行者123 更新时间:2023-11-28 18:31:41 26 4
gpt4 key购买 nike

在视频剪辑的帧子集中,我有六个点的 (x,y) 像素坐标。我想为这些数据点之间的帧(时间)的(x,y)像素值生成一个平滑的插值器。

Falcon 9 1st stage landing on Barge CRS-8

它们在下面显示为 x、y 中的轨迹,以及单独与时间的关系。

scipy.interpolate 中,有非常丰富的可能选择(许多不同类型的插值方法)。 我的问题是: 我应该从哪里开始?我正在寻找具有插值经验的人的推荐。 在 SciPy 中所有可用的插值方法中,为了插值此数据和类似数据,我应该首先尝试学习哪些方法?

一些可用的方法可以将 x 和 y 拟合在一起 - 例如MultivariateSplines 但不确定将它们一起处理或单独处理是否有优势。

注意:我只使用 NumPy 和 SciPy,请不要推荐其他软件包。谢谢!

如果您想查看数据,都在 paths = np.array... 行中:

import numpy as np
import matplotlib.pyplot as plt

# this line is very long - has all the data for the plot!
paths = np.array([[[45.0, 135.0], [42.0, 130.0], [41.0, 123.0], [41.0, 120.0], [38.0, 119.0], [35.0, 124.0], [34.0, 124.0], [36.0, 122.0], [36.0, 118.0], [37.0, 113.0], [41.0, 107.0], [45.0, 97.0], [49.0, 82.0], [54.0, 72.0], [56.0, 66.0], [57.0, 61.0], [58.0, 59.0], [57.0, 55.0], [-1, -1], [53.0, 47.0], [47.0, 41.0], [42.0, 35.0], [37.0, 27.0], [34.0, 23.0], [33.0, 21.0], [35.0, 23.0], [38.0, 23.0], [43.0, 21.0], [46.0, 17.0], [50.0, 16.0], [50.0, 19.0], [50.0, 26.0], [47.0, 35.0], [46.0, 41.0], [47.0, 44.0], [48.0, 48.0], [47.0, 51.0], [43.0, 55.0], [39.0, 56.0], [36.0, 52.0]], [[50.0, 139.0], [48.0, 135.0], [46.0, 128.0], [46.0, 125.0], [43.0, 124.0], [40.0, 128.0], [40.0, 130.0], [41.0, 127.0], [42.0, 124.0], [43.0, 120.0], [45.0, 112.0], [51.0, 102.0], [54.0, 91.0], [60.0, 79.0], [63.0, 70.0], [62.0, 67.0], [68.0, 62.0], [62.0, 62.0], [-1, -1], [63.0, 52.0], [53.0, 48.0], [49.0, 41.0], [44.0, 33.0], [40.0, 30.0], [40.0, 27.0], [41.0, 29.0], [44.0, 30.0], [48.0, 27.0], [52.0, 24.0], [56.0, 22.0], [58.0, 27.0], [56.0, 32.0], [54.0, 42.0], [52.0, 48.0], [53.0, 52.0], [55.0, 55.0], [54.0, 59.0], [50.0, 62.0], [45.0, 63.0], [42.0, 58.0]], [[113.0, 134.0], [110.0, 130.0], [110.0, 123.0], [110.0, 121.0], [107.0, 120.0], [105.0, 123.0], [105.0, 123.0], [107.0, 121.0], [108.0, 119.0], [110.0, 115.0], [113.0, 108.0], [118.0, 96.0], [-1, -1], [128.0, 72.0], [122.0, 68.0], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [127.0, 40.0], [123.0, 35.0], [118.0, 29.0], [116.0, 24.0], [115.0, 21.0], [117.0, 22.0], [122.0, 23.0], [128.0, 19.0], [-1, -1], [136.0, 15.0], [-1, -1], [138.0, 26.0], [137.0, 35.0], [136.0, 41.0], [138.0, 43.0], [140.0, 48.0], [140.0, 50.0], [137.0, 54.0], [134.0, 55.0], [133.0, 51.0]], [[192.0, 154.0], [190.0, 148.0], [191.0, 140.0], [192.0, 137.0], [191.0, 137.0], [188.0, 142.0], [189.0, 143.0], [193.0, 139.0], [193.0, 137.0], [197.0, 134.0], [203.0, 128.0], [208.0, 117.0], [217.0, 104.0], [219.0, 93.0], [223.0, 85.0], [226.0, 81.0], [228.0, 78.0], [228.0, 76.0], [228.0, 73.0], [226.0, 68.0], [224.0, 63.0], [220.0, 58.0], [217.0, 52.0], [216.0, 46.0], [216.0, 42.0], [219.0, 42.0], [223.0, 45.0], [230.0, 46.0], [236.0, 48.0], [244.0, 50.0], [247.0, 50.0], [248.0, 50.0], [246.0, 55.0], [245.0, 61.0], [249.0, 71.0], [254.0, 79.0], [257.0, 87.0], [256.0, 89.0], [253.0, 87.0], [251.0, 80.0]], [[216.0, 144.0], [214.0, 139.0], [215.0, 131.0], [216.0, 129.0], [217.0, 127.0], [213.0, 133.0], [214.0, 133.0], [217.0, 130.0], [219.0, 128.0], [222.0, 125.0], [227.0, 118.0], [234.0, 107.0], [239.0, 94.0], [245.0, 82.0], [249.0, 76.0], [253.0, 72.0], [255.0, 69.0], [255.0, 67.0], [255.0, 62.0], [254.0, 57.0], [251.0, 52.0], [248.0, 48.0], [245.0, 42.0], [244.0, 36.0], [245.0, 31.0], [249.0, 32.0], [252.0, 33.0], [259.0, 34.0], [267.0, 38.0], [273.0, 38.0], [277.0, 38.0], [278.0, 39.0], [276.0, 43.0], [276.0, 50.0], [280.0, 58.0], [286.0, 67.0], [288.0, 74.0], [288.0, 76.0], [286.0, 74.0], [286.0, 67.0]], [[252.0, 149.0], [250.0, 143.0], [252.0, 137.0], [253.0, 133.0], [252.0, 132.0], [250.0, 137.0], [252.0, 137.0], [255.0, 134.0], [257.0, 132.0], [262.0, 130.0], [266.0, 123.0], [273.0, 111.0], [277.0, 97.0], [286.0, 86.0], [289.0, 80.0], [293.0, 77.0], [295.0, 75.0], [296.0, 71.0], [296.0, 66.0], [296.0, 61.0], [294.0, 57.0], [290.0, 52.0], [288.0, 48.0], [289.0, 42.0], [289.0, 37.0], [293.0, 35.0], [298.0, 37.0], [305.0, 39.0], [313.0, 42.0], [319.0, 43.0], [324.0, 44.0], [325.0, 44.0], [324.0, 49.0], [325.0, 55.0], [329.0, 63.0], [336.0, 71.0], [339.0, 78.0], [339.0, 80.0], [337.0, 79.0], [338.0, 73.0]]])

paths[paths<0] = np.nan # turn the -1's back into np.nan

plt.figure()
for path in paths:
x, y = path.T
plt.plot(x, y, linewidth=3)
plt.plot(x, y, '.k')
plt.show()

plt.figure()
for i, path in enumerate(paths):
plt.subplot(6, 1, i+1)
x, y = path.T
plt.plot(x)
plt.plot(x, '.k')
plt.plot(y)
plt.plot(y, '.k')
plt.show()

(x, y) 2D plot of data

x and y 1D plot of data

最佳答案

我正在使用 scipy.interpolate.InterpolatedUnivariateSpline

我必须处理的一件事是某些方法往往会占用过多的内存空间 - 上面的函数在这方面运行良好。

关于python - 如何为缺少数据的移动对象坐标生成插值器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36566990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com