use of com.amazonaws.services.rekognition.model.TextTypes in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectPlainText.
private IdentifyTextResult detectPlainText(ByteBuffer imageData) throws PredictionsException {
DetectTextRequest request = new DetectTextRequest().withImage(new Image().withBytes(imageData));
// Read text in the given image via Amazon Rekognition
final DetectTextResult result;
try {
result = rekognition.detectText(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting text.", serviceException, "See attached service exception for more details.");
}
StringBuilder fullTextBuilder = new StringBuilder();
List<String> rawLineText = new ArrayList<>();
List<IdentifiedText> words = new ArrayList<>();
List<IdentifiedText> lines = new ArrayList<>();
for (TextDetection detection : result.getTextDetections()) {
TextTypes type = TextTypes.fromValue(detection.getType());
switch(type) {
case LINE:
rawLineText.add(detection.getDetectedText());
lines.add(RekognitionResultTransformers.fromTextDetection(detection));
continue;
case WORD:
fullTextBuilder.append(detection.getDetectedText()).append(" ");
words.add(RekognitionResultTransformers.fromTextDetection(detection));
continue;
default:
}
}
return IdentifyTextResult.builder().fullText(fullTextBuilder.toString().trim()).rawLineText(rawLineText).lines(lines).words(words).build();
}
Aggregations