How to access google cloud vision API in python program?

5 views
Skip to first unread message

user6745741 via StackOverflow

unread,
Jan 26, 2017, 7:11:05 AM1/26/17
to google-appengin...@googlegroups.com

I have signed up for free trial in google cloud platform.I created a project and OAuth 2.0 client IDs.I got a json file also.I installed required packages using

pip install --upgrade google-api-python-client
pip install google-cloud

Now i need to access text extraction from image API from google in my python program.My code is(here)

from google.cloud import vision
client = vision.Client()
with open('./image.jpg', 'rb') as image_file:
 image = client.image(content=image_file.read())
texts = image.detect_text()
print texts[0].description

I have JSON file,client id,Client secret.How to integrate these credintials in above code to access google api?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41873162/how-to-access-google-cloud-vision-api-in-python-program

danielx via StackOverflow

unread,
Jan 26, 2017, 7:26:05 AM1/26/17
to google-appengin...@googlegroups.com

To authenticate using a service account JSON keyfile you need to point to it using an environment variable:

$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"

You can also authenticate using the Google Cloud SDK if it's available

$ gcloud beta auth application-default login

https://googlecloudplatform.github.io/google-cloud-python/stable/google-cloud-auth.html#overview



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41873162/how-to-access-google-cloud-vision-api-in-python-program/41873413#41873413
Reply all
Reply to author
Forward
0 new messages