我使用以下代码:
import urllib, cStringIO
from PIL import Image
url='https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
file = cStringIO.StringIO(urllib.urlopen(url).read())
img = Image.open(file)
基于:How do I read image data from a URL in Python?
现在,我需要对其进行base64编码,以便发布到Google Cloud Vision API。怎么做?
或者Google Cloud Vision API是否与图片网址一起使用?
答案 0 :(得分:1)
假设没有必要解析图像,只需抓住它并对其进行编码:
import urllib2
import base64
url = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
contents = urllib2.urlopen(url).read()
data = base64.b64encode(contents)
print data