Last active
May 21, 2021 07:10
-
-
Save magicwenli/c7a1c891ed0b67353452ddfff1cc0e0b to your computer and use it in GitHub Desktop.
使用pillow将cv2读入的图片创建为GIF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import cv2 | |
import numpy as np | |
def make_gif(target_path, images, duration=80): | |
images[0].save(target_path, | |
save_all=True, append_images=images[1:], optimize=False, duration=duration, loop=1) | |
imgs=[] | |
for i in range(10): | |
# 随机图片 | |
randomByteArray = bytearray(os.urandom(120000)) | |
flatNumpyArray = numpy.array(randomByteArray) | |
RandomColor = flatNumpyArray.reshape(200, 200, 3) | |
imgs.append(RandomColor) | |
make_gif('src.gif', [Image.fromarray(cv2.cvtColor(x[0], cv2.COLOR_BGR2RGB)) for x in imgs]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment