Last active
August 29, 2015 14:01
-
-
Save cancan101/80e27feaef8eae0ed921 to your computer and use it in GitHub Desktop.
OpenCV Load GIF URL
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 requests | |
import tempfile | |
def load_gif_url(url): | |
with tempfile.NamedTemporaryFile(suffix=".gif") as f: | |
f.write(requests.get(url).content) | |
f.flush() | |
img = Image.open(f.name) | |
with tempfile.NamedTemporaryFile(suffix=".png") as f: | |
img.save(f.name) | |
f.flush() | |
src = cv2.imread(f.name) | |
assert src is not None and len(src), "Empty" | |
return src |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment