The Google Cloud Vision API Java samples have moved. This directory is no longer actively developed or maintained.
For new work on this check out the landmark detection vision sample in the Google Cloud Platform Java samples repository.
This sample takes in the URI for an object in Google Cloud Storage, and identifies the landmark pictured in it.
This sample uses the Apache Maven build system. Before getting started, be sure to download and install it. When you use Maven as described here, it will automatically download the needed client libraries.
-
Create a project with the Google Cloud Console, and enable the Vision API.
-
Set up your environment with Application Default Credentials. For example, from the Cloud Console, you might create a service account, download its json credentials file, then set the appropriate environment variable:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
-
Upload an image to Google Cloud Storage (for example, using gsutil or the GUI), and make sure the image is accessible to the default credentials you set up. Note that by default, Cloud Storage buckets and their associated objects are readable by service accounts within the same project. For example, if you're using gsutil, you might do:
gsutil mb gs://<your-project-bucket> gsutil cp landmark.jpg gs://<your-project-bucket>/landmark.jpg # This step is unnecessary with default permissions, but for completeness, # explicitly give the service account access to the image. This email can # be found by running: # `grep client_email /path/to/your-project-credentials.json` gsutil acl ch -u <[email protected]>:R \ gs://<your-project-bucket>/landmark.jpg
To build and run the sample, run the following from this directory:
mvn clean compile assembly:single
java -cp target/landmark-detection-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.landmarkdetection.DetectLandmark "gs://your-project-bucket/landmark.jpg"