如何在python中将图像序列显示为视频剪辑

2024-05-15 21:18:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个折叠的图像列表,是从视频剪辑中提取的帧。我想知道我怎样才能像剪辑一样顺序播放图像序列。(嗯,FPS不重要。) 在Python上检查PIL模块和skimage模块,除非我将JPG序列转换为GIF格式,否则我无法在Python上执行此操作。在


Tags: 模块图像列表pil顺序剪辑格式序列
1条回答
网友
1楼 · 发布于 2024-05-15 21:18:45

一种方法是使用matplotlib库的动画功能。以下是从online documentation复制/粘贴的示例:

#!/usr/bin/env python
"""
An animated image
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation 

def f(x, y):
    return np.sin(x) + np.cos(y)

x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)


fig = plt.figure()
im = plt.imshow(f(x, y))

def updatefig(*args):
    global x,y
    x += np.pi / 15.
    y += np.pi / 20.
    im.set_array(f(x,y))
    return im,

ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()

以下几点需要注意:

  • 每个图像都将被转换为numpy数组
  • 使用im.set_array(在updatefig函数中)加载下一个图像

相关问题 更多 >