use of com.google.cloud.automl.v1.Image in project openj9 by eclipse-openj9.
the class XMLIndexReader method _createCoreImageAfterParseError.
/**
* This is like the setJ9DumpData method but is to be used when we fail to parse the file. It is meant to try to construct the
* Image object with what it was able to get
*
* @param e The cause of the error
*/
private void _createCoreImageAfterParseError(Exception e) {
Builder builder = null;
if (_stream == null) {
// extract directly from the file
builder = new Builder(_coreFile, _reader, 0, _fileResolvingAgent);
} else {
// extract using the data stream
builder = new Builder(_coreFile, _stream, 0, _fileResolvingAgent);
}
_coreFile.extract(builder);
String osType = builder.getOSType();
String cpuType = builder.getCPUType();
String cpuSubType = builder.getCPUSubType();
long creationTime = builder.getCreationTime();
_coreImage = new Image(osType, null, cpuType, cpuSubType, 0, 0, creationTime);
Iterator spaces = builder.getAddressSpaces();
while (spaces.hasNext()) {
ImageAddressSpace addressSpace = (ImageAddressSpace) spaces.next();
// Set all processes as having invalid runtimes
for (Iterator processes = addressSpace.getProcesses(); processes.hasNext(); ) {
ImageProcess process = (ImageProcess) processes.next();
process.runtimeExtractionFailed(e);
}
_coreImage.addAddressSpace(addressSpace);
}
}
use of com.google.cloud.automl.v1.Image in project aem-core-wcm-components by adobe.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v2, rootPage, defaultPageTemplate, clientlibs, new Image());
}
use of com.google.cloud.automl.v1.Image in project spring-cloud-gcp by GoogleCloudPlatform.
the class CloudVisionTemplate method analyzeImage.
/**
* Analyze an image and extract the features of the image specified by {@code featureTypes}.
*
* <p>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 {@link Feature.Type}.
*
* @param imageResource the image one wishes to analyze. The Cloud Vision APIs support image
* formats described here: https://cloud.google.com/vision/docs/supported-files
* @param imageContext the image context used to customize the Vision API request
* @param featureTypes the types of image analysis to perform on the image
* @return 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
*/
public AnnotateImageResponse analyzeImage(Resource imageResource, ImageContext imageContext, Feature.Type... featureTypes) {
ByteString imgBytes;
try {
imgBytes = ByteString.readFrom(imageResource.getInputStream());
} catch (IOException ex) {
throw new CloudVisionException(READ_BYTES_ERROR_MESSAGE, ex);
}
Image image = Image.newBuilder().setContent(imgBytes).build();
List<Feature> featureList = Arrays.stream(featureTypes).map(featureType -> Feature.newBuilder().setType(featureType).build()).collect(Collectors.toList());
BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder().addRequests(AnnotateImageRequest.newBuilder().addAllFeatures(featureList).setImageContext(imageContext).setImage(image)).build();
BatchAnnotateImagesResponse batchResponse = this.imageAnnotatorClient.batchAnnotateImages(request);
List<AnnotateImageResponse> annotateImageResponses = batchResponse.getResponsesList();
if (!annotateImageResponses.isEmpty()) {
return annotateImageResponses.get(0);
} else {
throw new CloudVisionException(EMPTY_RESPONSE_ERROR_MESSAGE);
}
}
use of com.google.cloud.automl.v1.Image in project spring-cloud-gcp by GoogleCloudPlatform.
the class CloudVisionTemplate method extractTextFromFile.
/**
* Extract the text out of a file and return the result as a String.
*
* @param fileResource the file one wishes to analyze
* @param mimeType the mime type of the fileResource. Currently, only "application/pdf",
* "image/tiff" and "image/gif" are supported.
* @return 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
*/
public List<String> extractTextFromFile(Resource fileResource, String mimeType) {
AnnotateFileResponse response = analyzeFile(fileResource, mimeType, Type.DOCUMENT_TEXT_DETECTION);
List<AnnotateImageResponse> annotateImageResponses = response.getResponsesList();
if (annotateImageResponses.isEmpty()) {
throw new CloudVisionException(EMPTY_RESPONSE_ERROR_MESSAGE);
}
List<String> result = annotateImageResponses.stream().map(annotateImageResponse -> annotateImageResponse.getFullTextAnnotation().getText()).collect(Collectors.toList());
if (result.isEmpty() && response.getError().getCode() != Code.OK.getNumber()) {
throw new CloudVisionException(response.getError().getMessage());
}
return result;
}
use of com.google.cloud.automl.v1.Image in project spring-cloud-gcp by GoogleCloudPlatform.
the class CloudVisionTemplate method analyzeFile.
/**
* Analyze a file and extract the features of the image specified by {@code featureTypes}.
*
* <p>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 {@link Feature.Type}.
*
* @param 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.
* @param mimeType the mime type of the fileResource. Currently, only "application/pdf",
* "image/tiff" and "image/gif" are supported.
* @param featureTypes the types of image analysis to perform on the image
* @return 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
*/
public AnnotateFileResponse analyzeFile(Resource fileResource, String mimeType, Feature.Type... featureTypes) {
ByteString imgBytes;
try {
imgBytes = ByteString.readFrom(fileResource.getInputStream());
} catch (IOException ex) {
throw new CloudVisionException(READ_BYTES_ERROR_MESSAGE, ex);
}
InputConfig inputConfig = InputConfig.newBuilder().setMimeType(mimeType).setContent(imgBytes).build();
List<Feature> featureList = Arrays.stream(featureTypes).map(featureType -> Feature.newBuilder().setType(featureType).build()).collect(Collectors.toList());
BatchAnnotateFilesRequest request = BatchAnnotateFilesRequest.newBuilder().addRequests(AnnotateFileRequest.newBuilder().addAllFeatures(featureList).setInputConfig(inputConfig).build()).build();
BatchAnnotateFilesResponse response = this.imageAnnotatorClient.batchAnnotateFiles(request);
List<AnnotateFileResponse> annotateFileResponses = response.getResponsesList();
if (!annotateFileResponses.isEmpty()) {
return annotateFileResponses.get(0);
} else {
throw new CloudVisionException(EMPTY_RESPONSE_ERROR_MESSAGE);
}
}
Aggregations