use of com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest 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();
}
}
use of com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectModerationLabels.
private List<Label> detectModerationLabels(ByteBuffer imageData) throws PredictionsException {
DetectModerationLabelsRequest request = new DetectModerationLabelsRequest().withImage(new Image().withBytes(imageData));
// Detect moderation labels in the given image via Amazon Rekognition
final DetectModerationLabelsResult result;
try {
result = rekognition.detectModerationLabels(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting moderation labels.", serviceException, "See attached service exception for more details.");
}
List<Label> labels = new ArrayList<>();
for (ModerationLabel moderationLabel : result.getModerationLabels()) {
Label label = Label.builder().value(moderationLabel.getName()).confidence(moderationLabel.getConfidence()).parentLabels(Collections.singletonList(moderationLabel.getParentName())).build();
labels.add(label);
}
return labels;
}
Aggregations