Python 如何从视频中确定角速度?
考虑一个旋转车轮的视频,该视频已作为灰度读入。在本视频中,我标记了一个感兴趣的区域: 在ROI中,我对像素强度设置了一个阈值:强度小于50的每个像素都被降到0,强度大于50的每个像素都被降到255 根据这些信息,我创建了一个包含两列的.txt文件:一列包含时间戳,另一列包含ROI内像素强度的平均值: 根据这些信息,应该可以确定车轮的角速度。但我不知道如何做到这一点。有人有主意吗 以下是我迄今为止所尝试的:Python 如何从视频中确定角速度?,python,image-processing,video-processing,Python,Image Processing,Video Processing,考虑一个旋转车轮的视频,该视频已作为灰度读入。在本视频中,我标记了一个感兴趣的区域: 在ROI中,我对像素强度设置了一个阈值:强度小于50的每个像素都被降到0,强度大于50的每个像素都被降到255 根据这些信息,我创建了一个包含两列的.txt文件:一列包含时间戳,另一列包含ROI内像素强度的平均值: 根据这些信息,应该可以确定车轮的角速度。但我不知道如何做到这一点。有人有主意吗 以下是我迄今为止所尝试的: import numpy as np import pandas as pd from
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\u start\u time,spoke\u end\u time=None,None
对于idx,枚举中的像素(VideoPixelMean):
如果像素>150且VideoPixelMean[idx-1]<150:
如果不说话,开始时间:
辐条开始时间=视频时间戳[idx]
其他:
辐条结束时间=视频时间戳[idx]
打破
其他:
最后一个像素=0
t=辐射结束时间-辐射开始时间-应以秒为单位
θ=72
v_角度=(2*np.pi*THETA)/(360*t)
速度是否恒定,您是否计划在整个时间内平均?还是你希望它动态变化?@MarkSetchell:速度大约每5秒变化一次。谢谢你的回答!我认为你的想法和我的非常相似。事实证明,我的想法一直有效。我刚输入了错误的车轮半径。萨马克什,你知道如何跟踪其中一条轮辐从一帧到下一帧的运动吗?由此,可以计算出轮辐的角位移。但我不知道如何追踪它。。
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)