Class CloudVisionTemplate

java.lang.Object
com.google.cloud.spring.vision.CloudVisionTemplate

public class CloudVisionTemplate extends Object
Spring Template offering convenience methods for interacting with the Cloud Vision APIs.
Since:
1.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CloudVisionTemplate(com.google.cloud.vision.v1.ImageAnnotatorClient imageAnnotatorClient)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.cloud.vision.v1.AnnotateFileResponse
    analyzeFile(org.springframework.core.io.Resource fileResource, String mimeType, com.google.cloud.vision.v1.Feature.Type... featureTypes)
    Analyze a file and extract the features of the image specified by featureTypes.
    com.google.cloud.vision.v1.AnnotateImageResponse
    analyzeImage(org.springframework.core.io.Resource imageResource, com.google.cloud.vision.v1.Feature.Type... featureTypes)
    Analyze an image and extract the features of the image specified by featureTypes.
    com.google.cloud.vision.v1.AnnotateImageResponse
    analyzeImage(org.springframework.core.io.Resource imageResource, com.google.cloud.vision.v1.ImageContext imageContext, com.google.cloud.vision.v1.Feature.Type... featureTypes)
    Analyze an image and extract the features of the image specified by featureTypes.
    extractTextFromFile(org.springframework.core.io.Resource fileResource, String mimeType)
    Extract the text out of a file and return the result as a String.
    extractTextFromImage(org.springframework.core.io.Resource imageResource)
    Extract the text out of an image and return the result as a String.
    extractTextFromImage(org.springframework.core.io.Resource imageResource, com.google.cloud.vision.v1.ImageContext imageContext)
    Extract the text out of an image and return the result as a String.
    extractTextFromPdf(org.springframework.core.io.Resource fileResource)
    Extract the text out of a pdf and return the result as a String.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • CloudVisionTemplate

      public CloudVisionTemplate(com.google.cloud.vision.v1.ImageAnnotatorClient imageAnnotatorClient)
  • Method Details

    • extractTextFromImage

      public String extractTextFromImage(org.springframework.core.io.Resource imageResource)
      Extract the text out of an image and return the result as a String.
      Parameters:
      imageResource - the image one wishes to analyze
      Returns:
      the text extracted from the image aggregated to a String
      Throws:
      CloudVisionException - if the image could not be read or if text extraction failed
    • extractTextFromPdf

      public List<String> extractTextFromPdf(org.springframework.core.io.Resource fileResource)
      Extract the text out of a pdf and return the result as a String.
      Parameters:
      fileResource - the pdf one wishes to analyze
      Returns:
      the text extracted from the pdf as a string per page
      Throws:
      CloudVisionException - if the image could not be read or if text extraction failed
    • extractTextFromImage

      public String extractTextFromImage(org.springframework.core.io.Resource imageResource, com.google.cloud.vision.v1.ImageContext imageContext)
      Extract the text out of an image and return the result as a String.
      Parameters:
      imageResource - the image one wishes to analyze
      imageContext - the image context to customize the text extraction request
      Returns:
      the text extracted from the image aggregated to a String
      Throws:
      CloudVisionException - if the image could not be read or if text extraction failed
    • extractTextFromFile

      public List<String> extractTextFromFile(org.springframework.core.io.Resource fileResource, String mimeType)
      Extract the text out of a file and return the result as a String.
      Parameters:
      fileResource - the file one wishes to analyze
      mimeType - the mime type of the fileResource. Currently, only "application/pdf", "image/tiff" and "image/gif" are supported.
      Returns:
      the text extracted from the pdf as a string per page
      Throws:
      CloudVisionException - if the image could not be read or if text extraction failed
    • analyzeImage

      public com.google.cloud.vision.v1.AnnotateImageResponse analyzeImage(org.springframework.core.io.Resource imageResource, com.google.cloud.vision.v1.Feature.Type... featureTypes)
      Analyze an image and extract the features of the image specified by featureTypes.

      A feature describes the kind of Cloud Vision analysis one wishes to perform on an image, such as text detection, image labelling, facial detection, etc. A full list of feature types can be found in Feature.Type.

      Parameters:
      imageResource - the image one wishes to analyze. The Cloud Vision APIs support image formats described here: https://cloud.google.com/vision/docs/supported-files
      featureTypes - the types of image analysis to perform on the image
      Returns:
      the results of image analyses
      Throws:
      CloudVisionException - if the image could not be read or if a malformed response is received from the Cloud Vision APIs
    • analyzeImage

      public com.google.cloud.vision.v1.AnnotateImageResponse analyzeImage(org.springframework.core.io.Resource imageResource, com.google.cloud.vision.v1.ImageContext imageContext, com.google.cloud.vision.v1.Feature.Type... featureTypes)
      Analyze an image and extract the features of the image specified by featureTypes.

      A feature describes the kind of Cloud Vision analysis one wishes to perform on an image, such as text detection, image labelling, facial detection, etc. A full list of feature types can be found in Feature.Type.

      Parameters:
      imageResource - the image one wishes to analyze. The Cloud Vision APIs support image formats described here: https://cloud.google.com/vision/docs/supported-files
      imageContext - the image context used to customize the Vision API request
      featureTypes - the types of image analysis to perform on the image
      Returns:
      the results of image analyses
      Throws:
      CloudVisionException - if the image could not be read or if a malformed response is received from the Cloud Vision APIs
    • analyzeFile

      public com.google.cloud.vision.v1.AnnotateFileResponse analyzeFile(org.springframework.core.io.Resource fileResource, String mimeType, com.google.cloud.vision.v1.Feature.Type... featureTypes)
      Analyze a file and extract the features of the image specified by featureTypes.

      A feature describes the kind of Cloud Vision analysis one wishes to perform on a file, such as text detection, image labelling, facial detection, etc. A full list of feature types can be found in Feature.Type.

      Parameters:
      fileResource - the file one wishes to analyze. The Cloud Vision APIs support image formats described here: https://cloud.google.com/vision/docs/supported-files. Documents with more than 5 pages are not supported.
      mimeType - the mime type of the fileResource. Currently, only "application/pdf", "image/tiff" and "image/gif" are supported.
      featureTypes - the types of image analysis to perform on the image
      Returns:
      the results of file analyse
      Throws:
      CloudVisionException - if the file could not be read or if a malformed response is received from the Cloud Vision APIs