throw new CloudVisionException("Failed to read image bytes from provided resource.", ex); throw new CloudVisionException( "Failed to receive valid response Vision APIs; empty response received.");
/** * Extract the text out of an image and return the result as a String. * @param imageResource the image one wishes to analyze * @return the text extracted from the image aggregated to a String * @throws CloudVisionException if the image could not be read or if text extraction failed */ public String extractTextFromImage(Resource imageResource) { AnnotateImageResponse response = analyzeImage(imageResource, Type.TEXT_DETECTION); String result = response.getFullTextAnnotation().getText(); if (result.isEmpty() && response.getError().getCode() != Code.OK.getNumber()) { throw new CloudVisionException(response.getError().getMessage()); } return result; }
throw new CloudVisionException("Failed to read image bytes from provided resource.", ex); throw new CloudVisionException( "Failed to receive valid response Vision APIs; empty response received.");
/** * Extract the text out of an image and return the result as a String. * @param imageResource the image one wishes to analyze * @return the text extracted from the image aggregated to a String * @throws CloudVisionTemplate if the image could not be read or if text extraction failed */ public String extractTextFromImage(Resource imageResource) { AnnotateImageResponse response = analyzeImage(imageResource, Type.TEXT_DETECTION); String result = response.getFullTextAnnotation().getText(); if (result.isEmpty() && response.getError().getCode() != Code.OK.getNumber()) { throw new CloudVisionException(response.getError().getMessage()); } return result; }