Search in sources :

Example 1 with ModerationLabel

use of software.amazon.awssdk.services.rekognition.model.ModerationLabel in project aws-doc-sdk-examples by awsdocs.

the class DetectModerationLabels method detectModLabels.

// snippet-start:[rekognition.java2.detect_mod_labels.main]
public static void detectModLabels(RekognitionClient rekClient, String sourceImage) {
    try {
        InputStream sourceStream = new FileInputStream(sourceImage);
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        Image souImage = Image.builder().bytes(sourceBytes).build();
        DetectModerationLabelsRequest moderationLabelsRequest = DetectModerationLabelsRequest.builder().image(souImage).minConfidence(60F).build();
        DetectModerationLabelsResponse moderationLabelsResponse = rekClient.detectModerationLabels(moderationLabelsRequest);
        // Display the results
        List<ModerationLabel> labels = moderationLabelsResponse.moderationLabels();
        System.out.println("Detected labels for image");
        for (ModerationLabel label : labels) {
            System.out.println("Label: " + label.name() + "\n Confidence: " + label.confidence().toString() + "%" + "\n Parent:" + label.parentName());
        }
    } catch (RekognitionException | FileNotFoundException e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : ModerationLabel(software.amazon.awssdk.services.rekognition.model.ModerationLabel) SdkBytes(software.amazon.awssdk.core.SdkBytes) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Image(software.amazon.awssdk.services.rekognition.model.Image) DetectModerationLabelsResponse(software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsResponse) FileInputStream(java.io.FileInputStream) DetectModerationLabelsRequest(software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsRequest)

Aggregations

FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 DetectModerationLabelsRequest (software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsRequest)1 DetectModerationLabelsResponse (software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsResponse)1 Image (software.amazon.awssdk.services.rekognition.model.Image)1 ModerationLabel (software.amazon.awssdk.services.rekognition.model.ModerationLabel)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1