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 Details

  • Constructor Details

  • 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, 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 AnnotateImageResponse analyzeImage(org.springframework.core.io.Resource imageResource, 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 AnnotateImageResponse analyzeImage(org.springframework.core.io.Resource imageResource, ImageContext imageContext, 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 AnnotateFileResponse analyzeFile(org.springframework.core.io.Resource fileResource, String mimeType, 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