Rilevare le etichette in un'immagine utilizzando l'API Cloud Vision
Questa guida rapida mostra come:
- Creare un bucket Cloud Storage.
- Carica l'immagine su Cloud Storage e rendi il file accessibile pubblicamente.
- Invia una richiesta all'API Vision con l'immagine.
L'esecuzione di questi passaggi dovrebbe richiedere circa cinque minuti. Puoi archiviare fino a 5 GB di dati in Cloud Storage senza costi ed effettuare fino a 1000 richieste di funzionalità al mese all'API Vision senza costi.
Prima di iniziare
Se non l'hai ancora fatto, segui queste istruzioni per configurare il tuo progetto e creare un bucket Cloud Storage.
Configura il progetto
- 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.
-
Make sure 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.
-
Make sure 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.
Crea un bucket Cloud Storage
Invia una richiesta a Cloud Vision
Salva una versione locale del file di immagine di esempio (
demo-img.jpg
).Nella console Google Cloud , vai alla pagina Bucket in Cloud Storage.
Seleziona il bucket creato nella sezione precedente.
Fai clic su Carica file e seleziona la versione locale del file
demo-img.jpg
da caricare nel bucket Cloud Storage.Crediti immagine: Rohiim Ariful su Unsplash. Dopo il caricamento del file e la sua visualizzazione nel bucket Cloud Storage, condividi l'immagine pubblicamente.
Nella sezione Prova questo metodo, completa il modello interattivo di Explorer API sostituendo
cloud-samples-data/vision
nel campoimage.source.imageUri
con il nome del bucket Cloud Storage in cui hai caricato il filedemo-img.jpg
. Il corpo della richiesta dovrebbe essere simile al seguente:{ "requests": [ { "features": [ { "type": "LABEL_DETECTION" } ], "image": { "source": { "imageUri": "gs://cloud-samples-data/vision/demo-img.jpg" } } } ] }
Fai clic su Esegui per inviare la richiesta al servizio. La risposta JSON viene visualizzata dopo il corpo della richiesta.
Complimenti! Hai effettuato la tua prima richiesta images.annotate
a
Cloud Vision.
Esegui la pulizia
Per evitare addebiti non necessari di Google Cloud , utilizza la console Google Cloud per eliminare il bucket Cloud Storage (e il progetto) se non ti servono.
Passaggi successivi
- Visualizza un elenco di tutti i tipi di funzionalità e i relativi utilizzi.
- Inizia a utilizzare l'API Vision nella lingua di tua scelta utilizzando una libreria client dell'API Vision.
- Utilizza le guide pratiche per scoprire di più su funzionalità specifiche, visualizzare annotazioni di esempio e ottenere annotazioni per un singolo file o immagine.
- Scopri di più sull'annotazione batch di immagini e file (PDF/TIFF/GIF).
- Sfoglia un elenco completo di esempi di codice della libreria client.