我想将一个scikit-image函数(特别是模板匹配函数match_template)应用于mp4视频帧的h264编码.我的应用程序跟踪每帧的时间非常重要,但我知道帧速率,因此我可以从帧编号轻松计算.
请注意我运行的资源很少,我希望尽可能保持依赖性:numpy无论如何都需要,因为我打算使用scikit-image,我会避免导入(和编译)openCV只是为了阅读视频.
我看到的底部这个页scikit-image可以seamleassly存储为处理视频numpy阵列,从而获得这将是理想的.
在 Raspbian(Raspberry Pi 2)上,从我的脚本中删除的以下最小示例正确生成了一个 mp4 文件:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
def anim_lift(x, y):
#set up the figure
fig = plt.figure(figsize=(15, 9))
def animate(i):
# update plot
pointplot.set_data(x[i], y[i])
return pointplot
# First frame
ax0 = plt.plot(x,y)
pointplot, = ax0.plot(x[0], y[0], 'or')
anim = animation.FuncAnimation(fig, animate, repeat = False,
frames=range(1,len(x)),
interval=200,
blit=True, repeat_delay=1000)
anim.save('out.mp4')
plt.close(fig)
# Number of frames
nframes = 200
# Generate data
x = np.linspace(0, 100, num=nframes)
y = np.random.random_sample(np.size(x)) …Run Code Online (Sandbox Code Playgroud)