首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Numpy阵列视频在木星笔记本中的应用

Numpy阵列视频在木星笔记本中的应用
EN

Stack Overflow用户
提问于 2018-08-06 07:42:28
回答 1查看 2.9K关注 0票数 4

我有一组从视频中提取的边缘图像(使用cv2.Canny)。所以数组的大小是TxHxW。其中T是时间步骤,下面的参数是高度和宽度。

目前,我在木星笔记本上显示输出的方式有以下代码:

代码语言:javascript
复制
from IPython.display import HTML
import imageio

imageio.mimwrite('test2.mp4', edges, fps=30)
HTML("""
<video width="480" height="360" controls>
  <source src="{0}">
</video>
""".format('./test2.mp4'))

我觉得生活,写文件可能是不必要的,也许有一个更好的方法。如果有,请告诉我。重点是在木星笔记本上展示。

如果您需要一个测试用例,请让edges = np.random.randn(100, 80, 80)

解决方案1:

感谢下面@Alleo的评论。使用Ipython 7.6+,您可以执行以下操作:

代码语言:javascript
复制
import imageio; 
from IPython.display import Video; 
imageio.mimwrite('test2.mp4', edges, fps=30); 
Video('test2.mp4', width=480, height=360) #the width and height option as additional thing new in Ipython 7.6.1

不过,这仍然需要您编写文件。

EN

回答 1

Stack Overflow用户

发布于 2019-07-30 15:53:32

一种快速的方法(例如用于调试)是使用matplotlib inline和matplotlib animation包。像这样的东西对我起作用了

代码语言:javascript
复制
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import animation
from IPython.display import HTML

# np array with shape (frames, height, width, channels)
video = np.array([...]) 

fig = plt.figure()
im = plt.imshow(video[0,:,:,:])

plt.close() # this is required to not display the generated image

def init():
    im.set_data(video[0,:,:,:])

def animate(i):
    im.set_data(video[i,:,:,:])
    return im

anim = animation.FuncAnimation(fig, animate, init_func=init, frames=video.shape[0],
                               interval=50)
HTML(anim.to_html5_video())

视频将在具有指定帧的循环中再现(在上面的示例中,我将动画间隔设置为50 ms,即20 fps)。

请查看我对this question的答复,了解更多细节。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51702749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档