Like here How to download image using requests , but to memory, using http://docs.python-requests.org.
Asked
Active
Viewed 6,831 times
7
-
`request.get('http://...').content` – falsetru Oct 22 '14 at 14:24
-
Just use ```StringIO``` instead of opened file object and you can use answer you provided. – pavel_form Oct 22 '14 at 14:33
-
Ok. Thanks. cStringIO.StringIO(opened_session.get("url").content) – bo858585 Oct 22 '14 at 15:19
1 Answers
14
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()

Shawn Wang
- 761
- 8
- 9