gpt4 book ai didi

python - Python ImageIO 中动画 Gif 的自定义帧持续时间

转载 作者:太空狗 更新时间:2023-10-29 21:21:52 24 4
gpt4 key购买 nike

我一直在玩弄 Python 中的动画 gif,帧将由位于温室中的 Raspberry Pi 相机生成。我使用了 Almar's answer to a previous question 中推荐的 imageio 代码成功创建简单的 gif。

但是,我现在正在尝试减慢帧持续时间,但要查看 documentation for imageio找不到 mimsave 的任何引用,但请参阅 mimwrite ,它应该有四个参数。我看过 additional gif documentation并且可以看到有一个持续时间参数。

目前,我的代码如下所示:

exportname = "output.gif"
kargs = { 'duration': 5 }
imageio.mimsave(exportname, frames, 'GIF', kargs)

我收到以下错误:

Traceback (most recent call last):
File "makegif.py", line 23, in <module>
imageio.mimsave(exportname, frames, 'GIF', kargs)
TypeError: mimwrite() takes at most 3 arguments (4 given)

其中 frames 是 imageio.imread 对象的列表。这是为什么?

已更新以显示完整答案:这是一个示例,展示了如何使用 kwargs 使用 imageio 创建动画 gif 来更改帧持续时间。

import imageio
import os
import sys

if len(sys.argv) < 2:
print("Not enough args - add the full path")

indir = sys.argv[1]

frames = []

# Load each file into a list
for root, dirs, filenames in os.walk(indir):
for filename in filenames:
if filename.endswith(".jpg"):
print(filename)
frames.append(imageio.imread(indir + "/" + filename))


# Save them as frames into a gif
exportname = "output.gif"
kargs = { 'duration': 5 }
imageio.mimsave(exportname, frames, 'GIF', **kargs)

最佳答案

或者你可以这样调用它:

imageio.mimsave(exportname, frames, format='GIF', duration=5)

关于python - Python ImageIO 中动画 Gif 的自定义帧持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38433425/

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