use of com.amazonaws.services.rekognition.model.Image in project aws-doc-sdk-examples by awsdocs.
the class AddFacesToCollection method main.
public static void main(String[] args) throws Exception {
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
Image image = new Image().withS3Object(new S3Object().withBucket(bucket).withName(photo));
IndexFacesRequest indexFacesRequest = new IndexFacesRequest().withImage(image).withQualityFilter(QualityFilter.AUTO).withMaxFaces(1).withCollectionId(collectionId).withExternalImageId(photo).withDetectionAttributes("DEFAULT");
IndexFacesResult indexFacesResult = rekognitionClient.indexFaces(indexFacesRequest);
System.out.println("Results for " + photo);
System.out.println("Faces indexed:");
List<FaceRecord> faceRecords = indexFacesResult.getFaceRecords();
for (FaceRecord faceRecord : faceRecords) {
System.out.println(" Face ID: " + faceRecord.getFace().getFaceId());
System.out.println(" Location:" + faceRecord.getFaceDetail().getBoundingBox().toString());
}
List<UnindexedFace> unindexedFaces = indexFacesResult.getUnindexedFaces();
System.out.println("Faces not indexed:");
for (UnindexedFace unindexedFace : unindexedFaces) {
System.out.println(" Location:" + unindexedFace.getFaceDetail().getBoundingBox().toString());
System.out.println(" Reasons:");
for (String reason : unindexedFace.getReasons()) {
System.out.println(" " + reason);
}
}
}
use of com.amazonaws.services.rekognition.model.Image 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();
}
use of com.amazonaws.services.rekognition.model.Image in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectLabels.
private List<Label> detectLabels(ByteBuffer imageData) throws PredictionsException {
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageData));
// Detect labels in the given image via Amazon Rekognition
final DetectLabelsResult result;
try {
result = rekognition.detectLabels(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting labels.", serviceException, "See attached service exception for more details.");
}
List<Label> labels = new ArrayList<>();
for (com.amazonaws.services.rekognition.model.Label rekognitionLabel : result.getLabels()) {
List<String> parents = new ArrayList<>();
for (Parent parent : rekognitionLabel.getParents()) {
parents.add(parent.getName());
}
List<RectF> boxes = new ArrayList<>();
for (Instance instance : rekognitionLabel.getInstances()) {
boxes.add(RekognitionResultTransformers.fromBoundingBox(instance.getBoundingBox()));
}
Label amplifyLabel = Label.builder().value(rekognitionLabel.getName()).confidence(rekognitionLabel.getConfidence()).parentLabels(parents).boxes(boxes).build();
labels.add(amplifyLabel);
}
return labels;
}
Aggregations