Last active
April 2, 2016 01:08
-
-
Save hongseok/7bc4a27ed6de9afefb144af57ab74324 to your computer and use it in GitHub Desktop.
Google Vision API Python Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import json | |
import urllib2 | |
import base64 | |
API_KEY = "API_KEY" | |
API_URL = "https://vision.googleapis.com/v1/images:annotate?key=" + API_KEY | |
with open("faulkner.jpg", "rb") as image_file: | |
encoded_string = base64.b64encode(image_file.read()) | |
features = [{"type": "LABEL_DETECTION", "maxResults": 10}] | |
image = {"content": encoded_string} | |
request = {"image" : image, "features" : features} | |
body = { "requests": [request] } | |
req = urllib2.Request(API_URL) | |
req.add_header('Content-Type', 'application/json') | |
response = urllib2.urlopen(req, json.dumps(body)) | |
print response.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment