转换为动图
import imageio
import os
import numpy as np
def compose_gif():
cwd = os.getcwd()
img_paths = []
for img_path in os.listdir(cwd):
if img_path.endswith(".png"):
img_paths.append(img_path)
# 按照名字排序
img_paths.sort(key= lambda x:int(x[-20:-4]))
gif_images = []
for path in img_paths:
gif_images.append(imageio.imread(path))
imageio.mimsave("./test.gif",gif_images,fps=10)
compose_gif()