gpt4 book ai didi

python - 将图表叠加在视频上

转载 作者:太空宇宙 更新时间:2023-11-03 17:29:24 24 4
gpt4 key购买 nike

有没有解决方案可以打开 mp4 并覆盖图形(Matplotlib)或类似的东西?

类似于 this

最佳答案

您可以使用 openCV 从视频中获取帧,如 example 所示。 ,并使用 matplotlib 在顶部绘制图表,例如

import cv2
import matplotlib.pyplot as plt
import numpy as np

filename = './SampleVideo.mp4'
cap = cv2.VideoCapture(filename)

try:
frames = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
width = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
except AttributeError:
frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

fig, ax = plt.subplots(1,1)
plt.ion()
plt.show()

#Setup a dummy path
x = np.linspace(0,width,frames)
y = x/2. + 100*np.sin(2.*np.pi*x/1200)

for i in range(frames):
fig.clf()
flag, frame = cap.read()

plt.imshow(frame)
plt.plot(x,y,'k-', lw=2)
plt.plot(x[i],y[i],'or')
plt.pause(0.01)

if cv2.waitKey(1) == 27:
break

我从here获取视频.

关于python - 将图表叠加在视频上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32111705/

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