Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
O Spring Cloud Google Cloud oferece bibliotecas convenientes para interagir com a API Vision de um aplicativo Spring. Essas bibliotecas incluem classes de configuração automática e auxiliares e classes de modelo do Spring Boot Template para permitir que os desenvolvedores comecem a usar a API Vision rapidamente.
Se você já estiver familiarizado com o Spring Framework (em inglês), a Vision do Spring Cloud poderá facilitar o trabalho com a API Vision no seu aplicativo e reduzir a quantidade de código que você precisa escrever.
Nesta página, explicamos como adicionar a Vision do Spring Cloud a um aplicativo Java. Para informações detalhadas sobre o módulo, consulte a referência da Vision do Spring Cloud.
Configuração de dependência
Para começar a usar essa biblioteca, adicione o artefato spring-cloud-gcp-starter-vision ao seu projeto.
Coordenadas do Maven usando a BOM do Spring Cloud Google Cloud :
Para mais informações, consulte as instruções para configurar um ambiente para desenvolvedores Java. Não é preciso instalar a biblioteca de cliente Google Cloud para Java. O Spring Boot Starter instala a biblioteca de cliente automaticamente.
Análise de imagem
Depois de configurar as dependências da Vision do Spring Cloud Google Cloud no classpath, é possível começar imediatamente a processar suas imagens conseguindo uma instância de CloudVisionTemplate usando a injeção de dependência do Spring.
O CloudVisionTemplate é um wrapper em torno das bibliotecas de cliente da API Vision e permite processar imagens facilmente por meio da API Vision.
Para mais informações sobre os recursos CloudVisionTemplate, consulte a página de referência do modelo do Cloud Vision.
As seções a seguir contêm amostras de código para casos de uso comuns do
CloudVisionTemplate. Todos os snippets de código vêm do aplicativo de amostra Spring e Cloud Vision (em inglês).
Como conseguir os rótulos de classificação de uma imagem
O código abaixo extrai os rótulos de classificação de uma imagem, fornecendo descrições gerais do conteúdo da imagem.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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/)."]]