in code_examples/java_examples/image/java-add-faces-to-collection.java [21:57]
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);
}
}
}