1. 程式人生 > >關於opencv不能讀取GIF圖片

關於opencv不能讀取GIF圖片

由於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')