Reputation: 2028
Is there possible to imread image from web url using scipy misc, or am I obliged to save the image from web then imread and delete it? I could not find an elegant solution.
from scipy.misc import imread
url = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRtUPjSSDzevfy47QqVpd8v2Nrt49QNIXeAfE9ntEwYKJtnDZabwg'
img = imread(url, mode='RGB')
Upvotes: 0
Views: 2302
Reputation: 23637
imread
takes either a file name or a file object. You can open a url like a file with urllib.request.urlopen
(Python 3) and pass the file object to imread
.
from urllib.request import urlopen
from scipy.misc import imread
url = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRtUPjSSDzevfy47QqVpd8v2Nrt49QNIXeAfE9ntEwYKJtnDZabwg'
with urlopen(url) as file:
img = imread(file, mode='RGB')
For Python 2: urllib2.urlopen
Upvotes: 3