public class CloudVisionTemplate extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY_RESPONSE_ERROR_MESSAGE |
static String |
READ_BYTES_ERROR_MESSAGE |
Constructor and Description |
---|
CloudVisionTemplate(ImageAnnotatorClient imageAnnotatorClient) |
Modifier and Type | Method and Description |
---|---|
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 . |
AnnotateImageResponse |
analyzeImage(org.springframework.core.io.Resource imageResource,
Feature.Type... featureTypes)
Analyze an image and extract the features of the image specified by
featureTypes . |
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 . |
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.
|
String |
extractTextFromImage(org.springframework.core.io.Resource imageResource)
Extract the text out of an image and return the result as a String.
|
String |
extractTextFromImage(org.springframework.core.io.Resource imageResource,
ImageContext imageContext)
Extract the text out of an image and return the result as a String.
|
List<String> |
extractTextFromPdf(org.springframework.core.io.Resource fileResource)
Extract the text out of a pdf and return the result as a String.
|
public static final String READ_BYTES_ERROR_MESSAGE
public static final String EMPTY_RESPONSE_ERROR_MESSAGE
public CloudVisionTemplate(ImageAnnotatorClient imageAnnotatorClient)
public String extractTextFromImage(org.springframework.core.io.Resource imageResource)
imageResource
- the image one wishes to analyzeCloudVisionException
- if the image could not be read or if text extraction failedpublic List<String> extractTextFromPdf(org.springframework.core.io.Resource fileResource)
fileResource
- the pdf one wishes to analyzeCloudVisionException
- if the image could not be read or if text extraction failedpublic String extractTextFromImage(org.springframework.core.io.Resource imageResource, ImageContext imageContext)
imageResource
- the image one wishes to analyzeimageContext
- the image context to customize the text extraction requestCloudVisionException
- if the image could not be read or if text extraction failedpublic List<String> extractTextFromFile(org.springframework.core.io.Resource fileResource, String mimeType)
fileResource
- the file one wishes to analyzemimeType
- the mime type of the fileResource. Currently, only "application/pdf",
"image/tiff" and "image/gif" are supported.CloudVisionException
- if the image could not be read or if text extraction failedpublic AnnotateImageResponse analyzeImage(org.springframework.core.io.Resource imageResource, Feature.Type... featureTypes)
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
.
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 imageCloudVisionException
- if the image could not be read or if a malformed response is
received from the Cloud Vision APIspublic AnnotateImageResponse analyzeImage(org.springframework.core.io.Resource imageResource, ImageContext imageContext, Feature.Type... featureTypes)
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
.
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 imageCloudVisionException
- if the image could not be read or if a malformed response is
received from the Cloud Vision APIspublic AnnotateFileResponse analyzeFile(org.springframework.core.io.Resource fileResource, String mimeType, Feature.Type... featureTypes)
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
.
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 imageCloudVisionException
- if the file could not be read or if a malformed response is
received from the Cloud Vision APIsCopyright © 2022. All rights reserved.