use of com.amazonaws.services.rekognition.model.AmazonRekognitionException in project aws-doc-sdk-examples by awsdocs.
the class DetectFaces method main.
public static void main(String[] args) throws Exception {
// Change bucket to your S3 bucket that contains the image file.
// Change photo to your image file.
String photo = "input.jpg";
String bucket = "bucket";
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))).withAttributes(Attribute.ALL);
try {
DetectFacesResult result = rekognitionClient.detectFaces(request);
List<FaceDetail> faceDetails = result.getFaceDetails();
for (FaceDetail face : faceDetails) {
if (request.getAttributes().contains("ALL")) {
AgeRange ageRange = face.getAgeRange();
System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old.");
System.out.println("Here's the complete set of attributes:");
} else {
// non-default attributes have null values.
System.out.println("Here's the default set of attributes:");
}
ObjectMapper objectMapper = new ObjectMapper();
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.rekognition.model.AmazonRekognitionException in project aws-doc-sdk-examples by awsdocs.
the class DetectLabels method main.
public static void main(String[] args) throws Exception {
// Change bucket and photo to your S3 Bucket and image.
String photo = "photo";
String bucket = "bucket";
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))).withMaxLabels(10).withMinConfidence(75F);
try {
DetectLabelsResult result = rekognitionClient.detectLabels(request);
List<Label> labels = result.getLabels();
System.out.println("Detected labels for " + photo + "\n");
for (Label label : labels) {
System.out.println("Label: " + label.getName());
System.out.println("Confidence: " + label.getConfidence().toString() + "\n");
List<Instance> instances = label.getInstances();
System.out.println("Instances of " + label.getName());
if (instances.isEmpty()) {
System.out.println(" " + "None");
} else {
for (Instance instance : instances) {
System.out.println(" Confidence: " + instance.getConfidence().toString());
System.out.println(" Bounding box: " + instance.getBoundingBox().toString());
}
}
System.out.println("Parent labels for " + label.getName() + ":");
List<Parent> parents = label.getParents();
if (parents.isEmpty()) {
System.out.println(" None");
} else {
for (Parent parent : parents) {
System.out.println(" " + parent.getName());
}
}
System.out.println("--------------------");
System.out.println();
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.rekognition.model.AmazonRekognitionException 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.AmazonRekognitionException in project aws-doc-sdk-examples by awsdocs.
the class DetectLabelsLocalFile method main.
public static void main(String[] args) throws Exception {
// Change photo to the path and filename of your image.
String photo = "input.jpg";
ByteBuffer imageBytes;
try (InputStream inputStream = new FileInputStream(new File(photo))) {
imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
}
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageBytes)).withMaxLabels(10).withMinConfidence(77F);
try {
DetectLabelsResult result = rekognitionClient.detectLabels(request);
List<Label> labels = result.getLabels();
System.out.println("Detected labels for " + photo);
for (Label label : labels) {
System.out.println(label.getName() + ": " + label.getConfidence().toString());
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.rekognition.model.AmazonRekognitionException in project aws-doc-sdk-examples by awsdocs.
the class DetectModerationLabels method main.
public static void main(String[] args) throws Exception {
// Change the values of photo and bucket to your values.
String photo = "input.jpg";
String bucket = "bucket";
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectModerationLabelsRequest request = new DetectModerationLabelsRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))).withMinConfidence(60F);
try {
DetectModerationLabelsResult result = rekognitionClient.detectModerationLabels(request);
List<ModerationLabel> labels = result.getModerationLabels();
System.out.println("Detected labels for " + photo);
for (ModerationLabel label : labels) {
System.out.println("Label: " + label.getName() + "\n Confidence: " + label.getConfidence().toString() + "%" + "\n Parent:" + label.getParentName());
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
Aggregations