use of com.amazonaws.services.rekognition.model.DetectLabelsResult in project myrobotlab by MyRobotLab.
the class Rekognition method getLabels.
/**
* Hopefully, Label is serializable, otherwise it needs to return a list of
* POJOs.
*
* @return
*/
public List<Label> getLabels(ByteBuffer imageBytes) {
AmazonRekognition client = getClient();
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageBytes)).withMaxLabels(maxLabels).withMinConfidence(minConfidence);
DetectLabelsResult result = client.detectLabels(request);
List<Label> labels = result.getLabels();
lastImage = imageBytes;
lastLabels = labels;
return labels;
}
use of com.amazonaws.services.rekognition.model.DetectLabelsResult in project aws-doc-sdk-examples by awsdocs.
the class DetectLabels method main.
public static void main(String[] args) throws Exception {
// Change bucket and photo to your S3 Bucket and image.
String photo = "photo";
String bucket = "bucket";
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))).withMaxLabels(10).withMinConfidence(75F);
try {
DetectLabelsResult result = rekognitionClient.detectLabels(request);
List<Label> labels = result.getLabels();
System.out.println("Detected labels for " + photo + "\n");
for (Label label : labels) {
System.out.println("Label: " + label.getName());
System.out.println("Confidence: " + label.getConfidence().toString() + "\n");
List<Instance> instances = label.getInstances();
System.out.println("Instances of " + label.getName());
if (instances.isEmpty()) {
System.out.println(" " + "None");
} else {
for (Instance instance : instances) {
System.out.println(" Confidence: " + instance.getConfidence().toString());
System.out.println(" Bounding box: " + instance.getBoundingBox().toString());
}
}
System.out.println("Parent labels for " + label.getName() + ":");
List<Parent> parents = label.getParents();
if (parents.isEmpty()) {
System.out.println(" None");
} else {
for (Parent parent : parents) {
System.out.println(" " + parent.getName());
}
}
System.out.println("--------------------");
System.out.println();
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.rekognition.model.DetectLabelsResult in project aws-doc-sdk-examples by awsdocs.
the class DetectLabelsLocalFile method main.
public static void main(String[] args) throws Exception {
// Change photo to the path and filename of your image.
String photo = "input.jpg";
ByteBuffer imageBytes;
try (InputStream inputStream = new FileInputStream(new File(photo))) {
imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
}
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageBytes)).withMaxLabels(10).withMinConfidence(77F);
try {
DetectLabelsResult result = rekognitionClient.detectLabels(request);
List<Label> labels = result.getLabels();
System.out.println("Detected labels for " + photo);
for (Label label : labels) {
System.out.println(label.getName() + ": " + label.getConfidence().toString());
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.rekognition.model.DetectLabelsResult in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectLabels.
private List<Label> detectLabels(ByteBuffer imageData) throws PredictionsException {
DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageData));
// Detect labels in the given image via Amazon Rekognition
final DetectLabelsResult result;
try {
result = rekognition.detectLabels(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting labels.", serviceException, "See attached service exception for more details.");
}
List<Label> labels = new ArrayList<>();
for (com.amazonaws.services.rekognition.model.Label rekognitionLabel : result.getLabels()) {
List<String> parents = new ArrayList<>();
for (Parent parent : rekognitionLabel.getParents()) {
parents.add(parent.getName());
}
List<RectF> boxes = new ArrayList<>();
for (Instance instance : rekognitionLabel.getInstances()) {
boxes.add(RekognitionResultTransformers.fromBoundingBox(instance.getBoundingBox()));
}
Label amplifyLabel = Label.builder().value(rekognitionLabel.getName()).confidence(rekognitionLabel.getConfidence()).parentLabels(parents).boxes(boxes).build();
labels.add(amplifyLabel);
}
return labels;
}
Aggregations