Search in sources :

Example 1 with DetectModerationLabelsRequest

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();
    }
}
Also used : ModerationLabel(com.amazonaws.services.rekognition.model.ModerationLabel) AmazonRekognitionException(com.amazonaws.services.rekognition.model.AmazonRekognitionException) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) Image(com.amazonaws.services.rekognition.model.Image) DetectModerationLabelsResult(com.amazonaws.services.rekognition.model.DetectModerationLabelsResult) DetectModerationLabelsRequest(com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest)

Example 2 with DetectModerationLabelsRequest

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;
}
Also used : ModerationLabel(com.amazonaws.services.rekognition.model.ModerationLabel) AmazonClientException(com.amazonaws.AmazonClientException) Label(com.amplifyframework.predictions.models.Label) ModerationLabel(com.amazonaws.services.rekognition.model.ModerationLabel) ArrayList(java.util.ArrayList) PredictionsException(com.amplifyframework.predictions.PredictionsException) Image(com.amazonaws.services.rekognition.model.Image) DetectModerationLabelsResult(com.amazonaws.services.rekognition.model.DetectModerationLabelsResult) DetectModerationLabelsRequest(com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest)

Aggregations

DetectModerationLabelsRequest (com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest)2 DetectModerationLabelsResult (com.amazonaws.services.rekognition.model.DetectModerationLabelsResult)2 Image (com.amazonaws.services.rekognition.model.Image)2 ModerationLabel (com.amazonaws.services.rekognition.model.ModerationLabel)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 AmazonRekognitionException (com.amazonaws.services.rekognition.model.AmazonRekognitionException)1 S3Object (com.amazonaws.services.rekognition.model.S3Object)1 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 Label (com.amplifyframework.predictions.models.Label)1 ArrayList (java.util.ArrayList)1