def download_image(url):
response = requests.get(url, stream=True, timeout=5)
# TODO use grequests
# Raise exception on error
response.raise_for_status()
numpy_array = np.asarray(bytearray(response.raw.read()), dtype=np.uint8)
image = cv2.imdecode(numpy_array, cv2.IMREAD_COLOR)
# TODO: handle transparency (load using cv2.IMREAD_UNCHANGED and convert alpha layer to white?)
return image
评论列表
文章目录