考虑以灰度读入的旋转轮视频。在此视频中,我标记了一个感兴趣区域:
在 ROI 内,我对像素强度设置了一个阈值:强度小于 50 的每个像素都降为 0,强度大于 50 的每个像素都缩放为 255。
根据这些信息,我创建了一个包含两列的 .txt 文件:一列包含时间戳,另一列包含 ROI 内像素强度的平均值:here
应该可以根据此信息确定车轮的角速度。但我不确定如何做到这一点。有人有想法吗?
这是我到目前为止尝试过的:
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
VideoData = pd.read_csv('myData.txt', sep='\t')
VideoPixelMean = VideoData.iloc[:,1].values.tolist()
VideoTimestamp = VideoData.iloc[:,0].values.tolist()
SpokeList = []
for idx,el in enumerate(VideoPixelMean):
if el >= 150:
SpokeList.append(idx)
VideoVelocity=[]
VelocityTime = [0]
for idx,el in enumerate(SpokeList):
if idx == 0:
VideoVelocity.append(0)
else:
framesPassed = SpokeList[idx] - SpokeList[idx-1]
if framesPassed > 2:
velocity = 2*np.pi/360 * 72 * 50 * 30/framesPassed #each wheel has 5 spokes (the angle between two spokes is 72°) and a radius of 50mm; fps = 30
else:
velocity = 0
VideoVelocity.append(velocity)
velocityTime = VideoTimestamp[el]
VelocityTime.append(velocityTime)
不过我很确定结果不正确。
最佳答案
有趣的问题!请对我的话持保留态度。
对于我们的固定 ROI,速度可以通过以下方式确定:
测量到达下一个辐条所需的时间。为此,您可以在遇到暗像素后测量第一次出现的亮像素和下一次出现的亮像素。
D-L-L-L-L-D-D-D.....D-L-L-L-L
^ ^
当您识别出这些点时,获取以秒为单位的时间差 (t)
以获得耗时。
你计算的距离:
2π(r)(θ/360)
您可以通过以下方式获得垂直速度:
v_perp = 2π(r)(θ/360) / t
现在您可以将它除以 r
以获得角速度:
v_angular = 2πθ/360t
spoke_start_time, spoke_end_time = None, None
for idx, pixel in enumerate(VideoPixelMean):
if pixel > 150 and VideoPixelMean[idx-1] < 150:
if not spoke_start_time:
spoke_start_time = VideoTimestamp[idx]
else:
spoke_end_time = VideoTimestamp[idx]
break
else:
last_pixel = 0
t = spoke_end_time - spoke_start_time # This should be in seconds
THETA = 72
v_angular = (2 * np.pi * THETA) / (360 * t)
关于python - 如何确定视频的角速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56289682/