# 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](https://cloud.google.com/storage/pricing#cloud-storage-always-free) and make up to [1000 feature
requests](https://docs.cloud.google.com/vision/docs/pricing) 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

<br />

### Required roles

1.

   Make sure that you have the following role or roles on the project:

   **Storage Admin** (`roles/storage.admin`)

   #### Check for the roles

   1.
      In the Google Cloud console, go to the **IAM** page.

      [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)
   2. Select the project.
   3.
      In the **Principal** column, find all rows that identify you or a group that
      you're included in. To learn which groups you're included in, contact your
      administrator.

   4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.

   #### Grant the roles

   1.
      In the Google Cloud console, go to the **IAM** page.

      [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)
   2. Select the project.
   3. Click **Grant access**.
   4.
      In the **New principals** field, enter your user identifier.

      This is typically the email address for a Google Account.

   5. Click **Select a role**, then search for the role.
   6. To grant additional roles, click **Add
      another role** and add each additional role.
   7. Click **Save**.

<br />

### Create a Cloud Storage bucket

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

   [Go to Buckets](https://console.cloud.google.com/storage/browser)
2. Click **Create**.
3. On the **Create a bucket** page, enter your bucket information. To go to the next step, click **Continue** .
   1. 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.
   2. In the **Choose where to store your data** section, do the following:
      1. Select a [Location type](https://docs.cloud.google.com/storage/docs/locations.md.txt).
      2. Choose a location where your bucket's data is permanently stored from the **[Location type](https://docs.cloud.google.com/storage/docs/locations.md.txt#available-locations)** drop-down menu.
         - If you select the [dual-region](https://docs.cloud.google.com/storage/docs/locations.md.txt#location-dr) location type, you can also choose to enable [turbo replication](https://docs.cloud.google.com/storage/docs/availability-durability.md.txt#turbo-replication) by using the relevant checkbox.
      3. To set up [cross-bucket replication](https://docs.cloud.google.com/storage/docs/availability-durability.md.txt#cross-bucket-replication), select **Add cross-bucket replication via Storage Transfer Service** and follow these steps:

         #### Set up cross-bucket replication

         1. In the **Bucket** menu, select a bucket.
         2. In the **Replication settings** section,
            click **Configure** to configure settings for the
            replication job.

            The **Configure cross-bucket replication** pane
            appears.
            - To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click **Add a prefix**.
            - To set a storage class for the replicated objects, select a storage class from the **Storage class** menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
            - Click **Done**.
   3. In the **Choose how to store your data** section, do the following:
      1. In the **Set a default class** section, select the following: **Standard**.
      2. To enable [hierarchical namespace](https://docs.cloud.google.com/storage/docs/hns-overview.md.txt), in the **Optimize storage for data-intensive workloads** section, select **Enable hierarchical namespace on this bucket** . **Note:** You cannot enable hierarchical namespace in existing buckets.
   4. In the **Choose how to control access to objects** section, select whether or not your bucket enforces [public access prevention](https://docs.cloud.google.com/storage/docs/public-access-prevention.md.txt), and select an [access control method](https://docs.cloud.google.com/storage/docs/access-control.md.txt) for your bucket's objects. **Note:** You cannot change the **Prevent public access** setting if this setting is enforced at an [organization policy](https://docs.cloud.google.com/storage/docs/org-policy-constraints.md.txt#public-access-prevention).
   5. In the **Choose how to protect object data** section, do the following:
      - Select any of the options under **Data protection** that you want to set for your bucket.
        - To enable [soft delete](https://docs.cloud.google.com/storage/docs/soft-delete.md.txt), click the **Soft delete policy (For data recovery)** checkbox, and specify the number of days you want to retain objects after deletion.
        - To set [Object Versioning](https://docs.cloud.google.com/storage/docs/object-versioning.md.txt), click the **Object versioning (For version control)** checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
        - To enable the retention policy on objects and buckets, click the **Retention (For compliance)** checkbox, and then do the following:
          - To enable [Object Retention Lock](https://docs.cloud.google.com/storage/docs/object-lock.md.txt), click the **Enable object retention** checkbox.
          - To enable [Bucket Lock](https://docs.cloud.google.com/storage/docs/bucket-lock.md.txt), click the **Set bucket retention policy** checkbox, and choose a unit of time and a length of time for your retention period.
      - To choose how your object data will be encrypted, expand the **Data encryption** section (), and select a [**Data encryption** method](https://docs.cloud.google.com/storage/docs/encryption.md.txt).
4. Click **Create**.

<br />

## Make a request to Cloud Vision

1. Save a local version of the following sample image file ([`demo-img.jpg`](https://docs.cloud.google.com/static/vision/docs/images/demo-img.jpg)).

   ![Two women biking in Jakarta.](https://docs.cloud.google.com/static/vision/docs/images/demo-img.jpg) *Image credit*: [Rohiim Ariful](https://unsplash.com/photos/Iz2cMcT6BzU) on [Unsplash](https://unsplash.com/).
2. In the Google Cloud console, go to the Cloud Storage **Buckets** page.

   [Go to Buckets](https://console.cloud.google.com/storage/browser)
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.

5. After the file is uploaded and appears in the Cloud Storage bucket,
   [share the image publicly](https://docs.cloud.google.com/storage/docs/access-control/making-data-public.md.txt).

6. In the [Try this method](https://docs.cloud.google.com/vision/docs/detect-labels-image-api.md.txt#apis-explorer-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"
           }
         }
       }
     ]
   }
   ```

   <br />

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](https://docs.cloud.google.com/vision/docs/features-list.md.txt) and their uses.
- Get started with the Vision API in your language of choice by using a [Vision API Client
  Library](https://docs.cloud.google.com/vision/docs/quickstart-client-libraries).
- Use the [How-to guides](https://docs.cloud.google.com/vision/docs/how-to.md.txt) to learn more about specific features, see example annotations, and get annotations for an individual file or image.
- Learn about batch [image](https://docs.cloud.google.com/vision/docs/batch.md.txt) and [file](https://docs.cloud.google.com/vision/docs/file-small-batch.md.txt) (PDF/TIFF/GIF) annotation.
- Browse through a comprehensive list of client library code [samples](https://docs.cloud.google.com/vision/docs/samples.md.txt).