This directory contains samples for Google Cloud Vision API. [Google Cloud Vision API][0] allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content
[0]: https://cloud.google.com/vision/docs
Authentication is typically done through [Application Default Credentials][11], which means you do not have to change the code to authenticate as long as your environment has credentials. You have a few options for setting up authentication:
When running locally, use the [Google Cloud SDK][12]
gcloud beta auth application-default login
When running on App Engine or Compute Engine, credentials are already set-up. However, you may need to configure your Compute Engine instance with [additional scopes][13].
You can create a `Service Account key file`_. This file can be used to authenticate to Google Cloud Platform services from any environment. To use the file, set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to the path to the key file, for example:export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
[11]: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow [12]: https://cloud.google.com/compute/docs/authentication#using [13]: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
Install [pip][21] and [virtualenv][22] if you do not already have them.
Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
$ virtualenv env $ source env/bin/activateInstall the dependencies needed to run the samples.
$ pip install -r requirements.txt
[21]: https://pip.pypa.io/ [22]: https://virtualenv.pypa.io/
To run this sample:
$ python quickstart.pyTo run this sample:
$ python detect.py
usage: detect.py [-h]
{faces,faces-uri,labels,labels-uri,landmarks,landmarks-uri,text,text-uri,logos,logos-uri,safe-search,safe-search-uri,properties,properties-uri,web,web-uri,crophints,crophints-uri,fulltext,fulltext-uri}
...
This application demonstrates how to perform basic operations with the
Google Cloud Vision API.
Example Usage:
python detect.py text ./resources/wakeupcat.jpg
python detect.py labels ./resources/landmark.jpg
python detect.py web ./resources/landmark.jpg
python detect.py web-uri http://wheresgus.com/dog.JPG
python detect.py faces-uri gs://your-bucket/file.jpg
For more information, the documentation at
https://cloud.google.com/vision/docs.
positional arguments:
{faces,faces-uri,labels,labels-uri,landmarks,landmarks-uri,text,text-uri,logos,logos-uri,safe-search,safe-search-uri,properties,properties-uri,web,web-uri,crophints,crophints-uri,fulltext,fulltext-uri}
faces Detects faces in an image.
faces-uri Detects faces in the file located in Google Cloud
Storage or the web.
labels Detects labels in the file.
labels-uri Detects labels in the file located in Google Cloud
Storage or on the Web.
landmarks Detects landmarks in the file.
landmarks-uri Detects landmarks in the file located in Google Cloud
Storage or on the Web.
text Detects text in the file.
text-uri Detects text in the file located in Google Cloud
Storage or on the Web.
logos Detects logos in the file.
logos-uri Detects logos in the file located in Google Cloud
Storage or on the Web.
safe-search Detects unsafe features in the file.
safe-search-uri Detects unsafe features in the file located in Google
Cloud Storage or on the Web.
properties Detects image properties in the file.
properties-uri Detects image properties in the file located in Google
Cloud Storage or on the Web.
web detects web annotations given an image.
web-uri detects web annotations in the file located in google
cloud storage.
crophints detects crop hints in an image.
crophints-uri detects crop hints in the file located in google cloud
storage.
fulltext extracts full text from an image.
fulltext-uri extracts full text in the file located in google cloud
storage.
optional arguments:
-h, --help show this help message and exitThis sample uses the [Google Cloud Client Library for Python][1]. You can read the documentation for more details on API usage and use GitHub to [browse the source][2] and [report issues][3].
[1]: https://googlecloudplatform.github.io/google-cloud-python/ [2]: https://github.com/GoogleCloudPlatform/google-cloud-python [3]: https://github.com/GoogleCloudPlatform/google-cloud-python/issues [4]: https://cloud.google.com/sdk/