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);
}
}
Aggregations