Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Spring Cloud Google Cloud menawarkan library yang mudah digunakan
untuk berinteraksi dengan Vision API dari aplikasi Spring. Library ini
mencakup
kelas Konfigurasi Otomatis dan kelas tambahan,
serta kelas Spring Boot Template agar developer dapat mulai menggunakan
Vision API dengan cepat.
Jika Anda sudah terbiasa dengan
Spring Framework,
Spring Cloud Vision dapat
mempermudah penggunaan Vision API dalam aplikasi Anda dan
mengurangi jumlah kode yang perlu Anda tulis.
Halaman ini menjelaskan bagaimana cara menambahkan Spring Cloud Vision
ke aplikasi Java. Untuk mengetahui informasi mendetail tentang modul ini,
lihat referensi Spring Cloud Vision.
Penyiapan dependensi
Untuk mulai menggunakan library ini, tambahkan artefak spring-cloud-gcp-starter-vision
ke project Anda.
Koordinat Maven, dengan menggunakan Spring Cloud Google Cloud BOM:
Untuk mengetahui informasi selengkapnya, lihat petunjuk untuk menyiapkan lingkungan
pengembangan Java. Anda tidak perlu menginstal Google Cloud Client Library for Java; starter Spring Boot akan menginstal library klien secara otomatis.
Analisis gambar
Setelah mengonfigurasi dependensi Spring Cloud Google Cloud Vision di classpath, Anda dapat segera mulai memproses gambar dengan mendapatkan
instance CloudVisionTemplate menggunakan injeksi dependensi Spring.
CloudVisionTemplate adalah wrapper di sekitar Library Klien Vision API
yang memungkinkan Anda memproses gambar dengan mudah
melalui Vision API.
Untuk mengetahui informasi selengkapnya tentang fitur CloudVisionTemplate,
lihat halaman referensi template Cloud Vision.
Bagian berikut berisi contoh kode untuk kasus penggunaan umum
CloudVisionTemplate. Semua cuplikan kode berasal dari aplikasi contoh
Spring dan Cloud Vision.
Mendapatkan label klasifikasi untuk satu gambar
Kode di bawah ini mengekstrak label klasifikasi untuk satu gambar yang
memberikan deskripsi umum tentang konten gambar.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-21 UTC."],[],[],null,["# Using Vision with Spring framework\n\n[Spring Cloud Google Cloud](https://spring.io/projects/spring-cloud-gcp) offers convenient libraries\nto interface with the Vision API from a Spring application. These libraries\ninclude\n[Auto-Configuration and helper classes](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html)\nand Spring Boot Template classes to allow developers to get started\nwith the Vision API quickly.\n\nIf you're already familiar with the\n[Spring Framework](https://spring.io/projects/spring-framework), then\nSpring Cloud Vision can\nmake it easier to work with the Vision API in your application and\nreduce the amount of code that you need to write.\n\nThis page explains how to add Spring Cloud Vision to a Java\napplication. For detailed information about the module, see the\n[Spring Cloud Vision reference](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#cloud-vision).\n\nDependency setup\n----------------\n\nTo begin using this library, add the `spring-cloud-gcp-starter-vision` artifact\nto your project.\n\nMaven coordinates, using Spring Cloud Google Cloud BOM: \n\n \u003cdependencyManagement\u003e\n \u003cdependencies\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.cloud\u003c/groupId\u003e\n \u003cartifactId\u003espring-cloud-gcp-dependencies\u003c/artifactId\u003e\n \u003cversion\u003e1.2.8.RELEASE\u003c/version\u003e\n \u003ctype\u003epom\u003c/type\u003e\n \u003cscope\u003eimport\u003c/scope\u003e\n \u003c/dependency\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n \u003cartifactId\u003espring-boot-dependencies\u003c/artifactId\u003e\n \u003cversion\u003e${spring.version}\u003c/version\u003e\n \u003ctype\u003epom\u003c/type\u003e\n \u003cscope\u003eimport\u003c/scope\u003e\n \u003c/dependency\u003e\n \u003c/dependencies\u003e\n \u003c/dependencyManagement\u003e\n\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.cloud\u003c/groupId\u003e\n \u003cartifactId\u003espring-cloud-gcp-starter-vision\u003c/artifactId\u003e\n \u003c/dependency\u003e\n\nFor more information, see the instructions for [setting up a Java development\nenvironment](/java/docs/setup). You do not need to install the Google Cloud Client\nLibrary for Java; the Spring Boot starter installs the client library\nautomatically.\n\nImage analysis\n--------------\n\nAfter configuring the Spring Cloud Google Cloud Vision dependencies on your\nclasspath, you can immediately begin processing your images by getting\nan instance of `CloudVisionTemplate` using [Spring dependency injection](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-spring-beans-and-dependency-injection.html). \n\n @Autowired private CloudVisionTemplate cloudVisionTemplate;\n\nThe `CloudVisionTemplate` is a wrapper around the Vision API\nClient Libraries and lets you process images easily through the\nVision API.\nFor more information about the `CloudVisionTemplate` features, see\nthe [Cloud Vision template reference page](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#cloud-vision).\n\nThe following sections contain code samples for common use cases of\nthe `CloudVisionTemplate`. All code snippets come from the [Spring and\nCloud Vision sample application](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/vision/spring-framework).\n\n### Getting the classification labels for an image\n\nThe code below extracts the classification labels for an image, providing you\nwith general descriptions of image content. \n\n AnnotateImageResponse response =\n this.cloudVisionTemplate.analyzeImage(\n this.resourceLoader.getResource(imageUrl), Type.LABEL_DETECTION);\n\n Map\u003cString, Float\u003e imageLabels =\n response.getLabelAnnotationsList().stream()\n .collect(\n Collectors.toMap(\n EntityAnnotation::getDescription,\n EntityAnnotation::getScore,\n (u, v) -\u003e {\n throw new IllegalStateException(String.format(\"Duplicate key %s\", u));\n },\n LinkedHashMap::new));\n\n### Extracting the Text In an Image\n\nThe code sample below describes another common operation of extracting the text\nfrom an image. \n\n String textFromImage =\n this.cloudVisionTemplate.extractTextFromImage(this.resourceLoader.getResource(imageUrl));\n return \"Text from image: \" + textFromImage;\n\nWhat's next\n-----------\n\n- [Get started with\n Spring Cloud Google Cloud](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#getting-started).\n- Learn more about [using Spring Cloud Vision in your\n applications](https://googlecloudplatform.github.io/spring-cloud-gcp/4.1.3/reference/html/index.html#cloud-vision).\n- [File a GitHub issue](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues) to report a bug or ask a question about the module.\n- Get more information about [Spring Framework support on\n Google Cloud](/java/docs/reference/spring).\n- Try a codelab to [deploy and run an application that uses\n Spring Cloud Google Cloud](https://codelabs.developers.google.com/spring/)."]]