7

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

Community
  • 1
  • 1
bo858585
  • 117
  • 2
  • 10

1 Answers1

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