use of software.amazon.awssdk.services.rekognition.model.DetectLabelsResponse in project aws-doc-sdk-examples by awsdocs.
the class DetectLabels method detectImageLabels.
// snippet-start:[rekognition.java2.detect_labels.main]
public static void detectImageLabels(RekognitionClient rekClient, String sourceImage) {
try {
InputStream sourceStream = new URL("https://images.unsplash.com/photo-1557456170-0cf4f4d0d362?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bGFrZXxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80").openStream();
// InputStream sourceStream = new FileInputStream(sourceImage);
SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
// Create an Image object for the source image.
Image souImage = Image.builder().bytes(sourceBytes).build();
DetectLabelsRequest detectLabelsRequest = DetectLabelsRequest.builder().image(souImage).maxLabels(10).build();
DetectLabelsResponse labelsResponse = rekClient.detectLabels(detectLabelsRequest);
List<Label> labels = labelsResponse.labels();
System.out.println("Detected labels for the given photo");
for (Label label : labels) {
System.out.println(label.name() + ": " + label.confidence().toString());
}
} catch (RekognitionException | FileNotFoundException | MalformedURLException e) {
System.out.println(e.getMessage());
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
}
}
use of software.amazon.awssdk.services.rekognition.model.DetectLabelsResponse in project aws-doc-sdk-examples by awsdocs.
the class DetectLabelsS3 method getLabelsfromImage.
// snippet-start:[rekognition.java2.detect_labels_s3.main]
public static void getLabelsfromImage(RekognitionClient rekClient, String bucket, String image) {
try {
S3Object s3Object = S3Object.builder().bucket(bucket).name(image).build();
Image myImage = Image.builder().s3Object(s3Object).build();
DetectLabelsRequest detectLabelsRequest = DetectLabelsRequest.builder().image(myImage).maxLabels(10).build();
DetectLabelsResponse labelsResponse = rekClient.detectLabels(detectLabelsRequest);
List<Label> labels = labelsResponse.labels();
System.out.println("Detected labels for the given photo");
for (Label label : labels) {
System.out.println(label.name() + ": " + label.confidence().toString());
}
} catch (RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
Aggregations