Skip to content

Instantly share code, notes, and snippets.

@lockdef
Last active May 22, 2019 00:38
Show Gist options
  • Save lockdef/212d44e6e503d64f45ae3378a8c04f5d to your computer and use it in GitHub Desktop.
Save lockdef/212d44e6e503d64f45ae3378a8c04f5d to your computer and use it in GitHub Desktop.
画像のURLを受け取りNumpyのArrayに変換する
import requests
from io import BytesIO
from PIL import Image
import numpy as np
def url_to_image(url):
"""
url -> np.array (RGB)
"""
response = requests.get(url, stream=True)
if response.status_code == 200:
return np.array(Image.open(BytesIO(response.content)).convert('RGB'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment