Detect labels in an image by using the Cloud Vision API

This quickstart shows you how to:

  • Create a Cloud Storage bucket.
  • Upload your image to Cloud Storage and make the file publicly accessible.
  • Make a request to the Vision API with that image.

These steps should take about five minutes to complete. You can store up to 5 GB of data in Cloud Storage for no charge and make up to 1000 feature requests per month to the Vision API for no charge.

Before you begin

If you haven't done so already, use the following instructions to set up your project and create a Cloud Storage bucket.

Set up your project

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Vision API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Cloud Vision API.

    Enable the API

Create a Cloud Storage bucket

  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets page

  2. Click Create bucket.
  3. On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
    • For Name your bucket, enter a unique bucket name. Don't include sensitive information in the bucket name, because the bucket namespace is global and publicly visible.
    • For Choose where to store your data, do the following:
      • Select a Location type option.
      • Select a Location option.
    • For Choose a default storage class for your data, select the following: Standard.
    • For Choose how to control access to objects, select an Access control option.
    • For Advanced settings (optional), specify an encryption method, a retention policy, or bucket labels.
  4. Click Create.

Make a request to Cloud Vision

  1. Save a local version of the sample image file (demo-img.jpg).

  2. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  3. Select the bucket you created in the previous section.

  4. Click Upload Files and select the local version of the demo-img.jpg file to upload to your Cloud Storage bucket.

    The Upload files button.
    This is the image file that you just uploaded:
    Two women biking in Jakarta.
    Image credit: Rohiim Ariful on Unsplash.

  5. After the file is uploaded and appears in the Cloud Storage bucket, share the image publicly.

  6. In the Try this method section, complete the interactive API Explorer template by replacing cloud-samples-data/vision in the image.source.imageUri field with the name of the Cloud Storage bucket where you uploaded the demo-img.jpg file. The request body should look like the following:

    {
      "requests": [
        {
          "features": [
            {
              "type": "LABEL_DETECTION"
            }
          ],
          "image": {
            "source": {
              "imageUri": "gs://cloud-samples-data/vision/demo-img.jpg"
            }
          }
        }
      ]
    }

  7. Click Execute to send the request to the service. The JSON response appears after the request body.

Congratulations! You've made your first images.annotate request to Cloud Vision.

Clean up

To avoid unnecessary Google Cloud charges, use the Google Cloud console to delete your Cloud Storage bucket (and your project) if you don't need them.

What's next

  • See a list of all feature types and their uses.
  • Get started with the Vision API in your language of choice by using a Vision API Client Library.
  • Use the How-to guides to learn more about specific features, see example annotations, and get annotations for an individual file or image.
  • Learn about batch image and file (PDF/TIFF/GIF) annotation.
  • Browse through a comprehensive list of client library code samples.