关于opencv不能读取GIF图片

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zjucor/article/details/83013356

由于license的原因,无法读取GIF:http://answers.opencv.org/question/185929/how-to-read-gif-in-python/

但是可以用其他库(PIL,Imageio)读取,保存为PNG,JPG的图片,然后opencv就能读取了

https://stackoverflow.com/questions/18502508/is-there-a-way-to-read-a-truncated-gif-with-pil

import cv2
from PIL import Image
gif = cv2.VideoCapture('file.gif')
ret,frame = gif.read() # ret=True if it finds a frame else False. Since your gif contains only one frame, the next read() will give you ret=False
img = Image.fromarray(frame)
img = img.convert('RGB')

猜你喜欢

转载自blog.csdn.net/zjucor/article/details/83013356