Mendeteksi label dalam gambar dengan menggunakan Cloud Vision API
Panduan memulai ini menunjukkan cara:
- Membuat bucket Cloud Storage.
- Upload gambar Anda ke Cloud Storage dan buat file tersebut dapat diakses secara publik.
- Buat permintaan ke Vision API dengan gambar tersebut.
Perlu waktu sekitar lima menit untuk menyelesaikan langkah-langkah ini. Anda dapat menyimpan hingga 5 GB data di Cloud Storage tanpa biaya dan membuat hingga 1.000 permintaan fitur per bulan ke Vision API tanpa biaya.
Sebelum memulai
Jika Anda belum melakukannya, gunakan petunjuk berikut untuk menyiapkan project dan membuat bucket Cloud Storage.
Menyiapkan project
- 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.
Membuat bucket Cloud Storage
- 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.
Membuat permintaan ke Cloud Vision
Simpan versi lokal file gambar sampel (
demo-img.jpg
).Di Google Cloud konsol, buka halaman Bucket Cloud Storage.
Pilih bucket yang Anda buat di bagian sebelumnya.
Klik Upload Files lalu pilih versi lokal file
demo-img.jpg
yang akan diupload ke bucket Cloud Storage Anda.Kredit gambar: Rohiim Ariful nyala Unsplash. Setelah file diupload dan muncul di bucket Cloud Storage, bagikan gambar secara publik.
Di bagian Cobalah metode ini, lengkapi template API Explorer interaktif dengan mengganti
cloud-samples-data/vision
di kolomimage.source.imageUri
dengan nama bucket Cloud Storage tempat Anda mengupload filedemo-img.jpg
. Isi permintaan akan terlihat seperti berikut:{ "requests": [ { "features": [ { "type": "LABEL_DETECTION" } ], "image": { "source": { "imageUri": "gs://cloud-samples-data/vision/demo-img.jpg" } } } ] }
Klik Execute untuk mengirim permintaan ke layanan. Respons JSON muncul setelah isi permintaan.
Selamat! Anda telah membuat permintaan images.annotate
pertama ke Cloud Vision.
Pembersihan
Untuk menghindari tagihan Google Cloud yang tidak perlu, gunakan konsol Google Cloud untuk menghapus bucket Cloud Storage (dan project Anda) jika Anda tidak membutuhkannya.
Langkah berikutnya
- Lihat daftar semua jenis fitur dan penggunaannya.
- Mulai Vision API dalam bahasa pilihan Anda dengan menggunakan Library Klien Vision API.
- Gunakan Panduan cara kerja untuk mempelajari lebih lanjut fitur tertentu, melihat contoh anotasi, dan mendapatkan anotasi untuk setiap file atau gambar.
- Pelajari anotasi gambar dan file (PDF/TIFF/GIF) dalam batch.
- Lihat daftar lengkap contoh kode library klien.