Python 从图像URL获取图像数据的几种方式

线上服务器获取图像大都是从URL获取, 总结 Python 环境下, 以下几种从图像 URL 获取图像数据

PIL.Image + requests

import requests as req
from PIL import Image
from io import BytesIO

response = req.get(img_url)
image = Image.open(BytesIO(response.content))

skimage

from skimage import io
image = io.imread(img_url)

OpenCV + Numpy + urllib

import numpy as np
import urllib
import cv2

resp = urllib.urlopen(img_url)
image = np.asarray(bytearray(resp.read()), dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)