Détecter des étiquettes dans une image à l'aide de l'API Cloud Vision
Ce guide de démarrage rapide vous montre comment :
- créer un bucket Cloud Storage ;
- importer votre image dans Cloud Storage et rendre le fichier accessible au public ;
- envoyer une requête à l'API Vision avec cette image.
Ces étapes devraient durer environ cinq minutes. Vous pouvez stocker sans frais jusqu'à 5 Go de données dans Cloud Storage et envoyer jusqu'à 1 000 demandes de fonctionnalité par mois à l'API Vision sans frais.
Avant de commencer
Si vous ne l'avez pas déjà fait, suivez les instructions ci-dessous pour configurer votre projet et créer un bucket Cloud Storage.
Configurer votre projet
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Vision API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Vision API.
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- 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.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
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.
-
In the Choose how to store your data section, do the following:
- In the Set a default class section, select the following: Standard.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
-
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, 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, 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, click the Enable object retention checkbox.
- To enable Bucket Lock, 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 (Data encryption method. ), and select a
- Select any of the options under Data protection that you
want to set for your bucket.
- Click Create.
Enregistrez une version locale de l'exemple de fichier image (
demo-img.jpg
).Dans la console Google Cloud , accédez à la page Buckets de Cloud Storage.
Sélectionnez le bucket que vous avez créé dans la section précédente.
Cliquez sur Importer des fichiers et sélectionnez la version locale du fichier
demo-img.jpg
à importer dans votre bucket Cloud Storage.Crédit image : Rohiim Ariful sur Unsplash Une fois le fichier importé et présent dans le bucket Cloud Storage, rendez l'image publique.
Dans la section Essayer cette méthode, renseignez le modèle interactif d'explorateur API en remplaçant
cloud-samples-data/vision
dans le champimage.source.imageUri
par le nom du bucket Cloud Storage dans lequel vous avez importé le fichierdemo-img.jpg
. Le corps de la requête doit se présenter comme suit :{ "requests": [ { "features": [ { "type": "LABEL_DETECTION" } ], "image": { "source": { "imageUri": "gs://cloud-samples-data/vision/demo-img.jpg" } } } ] }
Cliquez sur Exécuter pour envoyer la requête au service. La réponse JSON s'affiche après le corps de la requête.
- Consultez la liste de tous les types de fonctionnalités et leur utilisation.
- Commencez à utiliser l'API Vision dans le langage de votre choix grâce à la bibliothèque cliente de l'API Vision.
- Utilisez les guides d'utilisation pour en savoir plus sur des fonctionnalités spécifiques, voir des exemples d'annotations et obtenir des annotations pour un fichier ou une image spécifiques.
- Apprenez-en plus sur l'annotation par lot des images et fichiers (PDF/TIFF/GIF).
- Parcourez une liste complète d'exemples de code de bibliothèques clientes.
Créer un bucket Cloud Storage
Envoyer une requête à Cloud Vision
Félicitations ! Vous avez envoyé votre première requête images.annotate
à Cloud Vision.
Effectuer un nettoyage
Pour éviter des frais Google Cloud inutiles, supprimez votre bucket Cloud Storage (et votre projet) à l'aide de la console Google Cloud si vous n'en avez plus besoin.