【问题标题】:How to find the smoothest part of the trajectory using python?如何使用python找到轨迹中最平滑的部分?
【发布时间】:2021-03-27 05:40:21
【问题描述】:

我遇到了以下问题。我创建了一个程序,可以估计摄像机沿 x 和 y 轴录制视频的轨迹。这种方法在翘曲稳定器中非常常见。我想找到代表最稳定视频片段的值范围并获得它们的值。这是轨迹图。 Graph 基于 numpy 数组。我想最好的办法是选择增加值最慢的部分,但我不知道该怎么做。

【问题讨论】:

  • 你想分别知道X和Y最稳定的部分吗?您想知道在某个值之前稳定的最长值范围,还是尽可能稳定的特定长度值?
  • 您好,是的,X 和 Y 部分都很重要。我想确保镜头中没有极端的平移或倾斜。我只对可用的框架范围感兴趣。但是有一个工具可以让我找出 X 或 Y 中最稳定的部分就可以了 :) 我想尽可能多地获得稳定的视频,对我来说最少是 25 帧。

标签: python opencv video computer-vision


【解决方案1】:

以下代码将找到 X 和 Y 在某个阈值下稳定的最长值范围。此阈值限制 X 和 Y 的变化。 您可以使用它来调整结果。 如果您想要更稳定的部分,请选择更低的 epsilon。 这将导致更短的范围。

import numpy as np
X=150*np.random.rand(270) # mock data as I do not have yours
Y=150*np.random.rand(270) # Replace X and Y with your X and Y data

epsilon = 80 #threshold

# get indexes where the difference is smaller than the threshold for X and Y
valid_values = np.logical_and(np.abs(np.diff(X))<epsilon,np.abs(np.diff(Y))<epsilon)
cummulative_valid_values=[]
count = 0

# find longest range of values that satisfy the threshold
for id,value in enumerate(valid_values):
    if value == True:
        count=count+1
    else:
        count = 0
    cummulative_valid_values.append(count)

# Calculate start and end of largest stable range
end_of_range = cummulative_valid_values.index(max(cummulative_valid_values))+1
start_of_range = end_of_range-max(cummulative_valid_values)+1

print("Largest stable range is: ",start_of_range," - ",end_of_range)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2012-12-08
    相关资源
    最近更新 更多