Python image processing directly from the Internet

I am writing python code to take an image from the Internet and calculate the standard deviation, ... and do other image processing with it. I have the following code:

from scipy import ndimage  
from urllib2 import urlopen  
from urllib import urlretrieve  
import urllib2  
import Image  
import ImageFilter  

def imagesd(imagelist):  
 for imageurl in imagelist:  
     opener1 = urllib2.build_opener()  
     page1 = opener1.open(imageurl)  
     im = page1.read()  
     #localfile = urlretrieve(  
     #img = Image.fromstring("RGBA", (1,1), page1.read())  
     #img = list(im.getdata())  
     # page1.read()  
     print img  
     #standard_deviation(p   

Now I keep going back and forth because I'm not sure how to take the image directly from the Internet without saving it to disk and passing it to the standard reject function.

Any hints / help would be greatly appreciated.

Thank.

+3
source share
1 answer

PIL ( Python Imaging Library) from fromstring frombuffer , . page1.read(), . PIL , "Image.open", , (,.jpg, gif, .png )

- :

from cStringIO import StringIO
(...)
    data = StringIO(page1.read())
    img = Image.open(data)
+4

Source: https://habr.com/ru/post/1730181/


All Articles