use of com.amazonaws.services.rekognition.model.DetectTextResult in project aws-doc-sdk-examples by awsdocs.
the class DetectText method main.
public static void main(String[] args) throws Exception {
// Change the value of bucket to the S3 bucket that contains your image file.
// Change the value of photo to your image file name.
String photo = "inputtext.jpg";
String bucket = "bucket";
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectTextRequest request = new DetectTextRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)));
try {
DetectTextResult result = rekognitionClient.detectText(request);
List<TextDetection> textDetections = result.getTextDetections();
System.out.println("Detected lines and words for " + photo);
for (TextDetection text : textDetections) {
System.out.println("Detected: " + text.getDetectedText());
System.out.println("Confidence: " + text.getConfidence().toString());
System.out.println("Id : " + text.getId());
System.out.println("Parent Id: " + text.getParentId());
System.out.println("Type: " + text.getType());
System.out.println();
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.rekognition.model.DetectTextResult 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