Detectar rótulos em uma imagem usando a API Cloud Vision
Neste guia de início rápido, você aprende a:
- Criar um bucket do Cloud Storage.
- Fazer upload de uma imagem no Cloud Storage e tornar o arquivo acessível publicamente.
- Fazer uma solicitação para a API Vision com a imagem
Essas etapas levam cerca de cinco minutos. É possível armazenar até 5 GB de dados no Cloud Storage sem custo financeiro e fazer até 1.000 solicitações de recursos por mês para a API Vision sem custo financeiro.
Antes de começar
Se você ainda não fez isso, use as instruções a seguir para configurar o projeto e criar um bucket do Cloud Storage.
Criar o projeto
- 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.
Salve uma versão local do arquivo de imagem de exemplo (
demo-img.jpg
).No console do Google Cloud , acesse a página Buckets do Cloud Storage.
Selecione o bucket que você criou na seção anterior.
Clique em Fazer upload de arquivos e selecione a versão local do arquivo
demo-img.jpg
para fazer upload para o bucket do Cloud Storage.Crédito da imagem: Rohiim Ariful em Unsplash. Depois que o arquivo for enviado e aparecer no bucket do Cloud Storage, compartilhe a imagem publicamente.
Na seção Testar este método, preencha o modelo interativo do API Explorer substituindo
cloud-samples-data/vision
no campoimage.source.imageUri
pelo nome do bucket do Cloud Storage no qual foi feito upload do arquivodemo-img.jpg
. O corpo da solicitação deve ficar assim:{ "requests": [ { "features": [ { "type": "LABEL_DETECTION" } ], "image": { "source": { "imageUri": "gs://cloud-samples-data/vision/demo-img.jpg" } } } ] }
Clique em Executar para enviar a solicitação ao serviço. A resposta JSON aparece após o corpo da solicitação.
- Veja uma lista de todos os tipos de recurso e os respectivos usos.
- Comece a usar a API Vision na linguagem de sua preferência com uma biblioteca de cliente da API Vision.
- Use os guias de instruções para saber mais sobre recursos específicos, conferir anotações de exemplo e anotações para um arquivo ou imagem individual.
- Saiba mais sobre a anotação de imagem e arquivo (PDF/TIFF/GIF) em lote.
- Navegue por uma lista abrangente de exemplos de código de biblioteca de cliente.
Criar um bucket do Cloud Storage
Fazer uma solicitação ao Cloud Vision
Parabéns! Você fez sua primeira solicitação images.annotate
ao Cloud Vision.
Limpar
Para evitar cobranças desnecessárias do Google Cloud , use o console do Google Cloud para excluir o bucket do Cloud Storage (e seu projeto) se você não precisar deles.