Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download image to memory using python requests?

Like here How to download image using requests , but to memory, using http://docs.python-requests.org.

like image 974
bo858585 Avatar asked Oct 22 '14 14:10

bo858585


1 Answers

You can use the following code, the image data will be set in img, not a file in the disk, than you can manipulate it with opencv.

import io
import requests
from PIL import Image
import matplotlib.pyplot as plt  
url = 'http://example.com/img.jpg'
data = requests.get(url).content
img = Image.open(io.BytesIO(data))
plt.imshow(img)
plt.show()
like image 97
Shawn Wang Avatar answered Nov 06 '22 09:11

Shawn Wang