Package com.google.cloud.spring.vision
Class CloudVisionTemplate
java.lang.Object
com.google.cloud.spring.vision.CloudVisionTemplate
Spring Template offering convenience methods for interacting with the Cloud Vision APIs.
- Since:
- 1.1
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCloudVisionTemplate
(com.google.cloud.vision.v1.ImageAnnotatorClient imageAnnotatorClient) -
Method Summary
Modifier and TypeMethodDescriptioncom.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 byfeatureTypes
.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 byfeatureTypes
.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 byfeatureTypes
.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.
-
Field Details
-
READ_BYTES_ERROR_MESSAGE
- See Also:
-
EMPTY_RESPONSE_ERROR_MESSAGE
- See Also:
-
-
Constructor Details
-
CloudVisionTemplate
public CloudVisionTemplate(com.google.cloud.vision.v1.ImageAnnotatorClient imageAnnotatorClient)
-
-
Method Details
-
extractTextFromImage
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
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 analyzeimageContext
- 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 analyzemimeType
- 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 byfeatureTypes
.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-filesfeatureTypes
- 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 byfeatureTypes
.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-filesimageContext
- the image context used to customize the Vision API requestfeatureTypes
- 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 byfeatureTypes
.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
-