use of com.amazonaws.services.rekognition.model.Label 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.Label 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.Label 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.Label in project aws-doc-sdk-examples by awsdocs.
the class VideoDetect method GetResultsLabels.
// Gets the results of labels detection by calling GetLabelDetection. Label
// detection is started by a call to StartLabelDetection.
private static void GetResultsLabels() throws Exception {
int maxResults = 10;
String paginationToken = null;
GetLabelDetectionResult labelDetectionResult = null;
do {
if (labelDetectionResult != null) {
paginationToken = labelDetectionResult.getNextToken();
}
GetLabelDetectionRequest labelDetectionRequest = new GetLabelDetectionRequest().withJobId(startJobId).withSortBy(LabelDetectionSortBy.TIMESTAMP).withMaxResults(maxResults).withNextToken(paginationToken);
labelDetectionResult = rek.getLabelDetection(labelDetectionRequest);
VideoMetadata videoMetaData = labelDetectionResult.getVideoMetadata();
System.out.println("Format: " + videoMetaData.getFormat());
System.out.println("Codec: " + videoMetaData.getCodec());
System.out.println("Duration: " + videoMetaData.getDurationMillis());
System.out.println("FrameRate: " + videoMetaData.getFrameRate());
// Show labels, confidence and detection times
List<LabelDetection> detectedLabels = labelDetectionResult.getLabels();
for (LabelDetection detectedLabel : detectedLabels) {
long seconds = detectedLabel.getTimestamp();
Label label = detectedLabel.getLabel();
System.out.println("Millisecond: " + Long.toString(seconds) + " ");
System.out.println(" Label:" + label.getName());
System.out.println(" Confidence:" + detectedLabel.getLabel().getConfidence().toString());
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();
}
} while (labelDetectionResult != null && labelDetectionResult.getNextToken() != null);
}
use of com.amazonaws.services.rekognition.model.Label in project myrobotlab by MyRobotLab.
the class Rekognition method main.
public static void main(String[] args) throws Exception {
Rekognition recog = (Rekognition) Runtime.start("recog", "Rekognition");
/*
* OpenCV opencv = (OpenCV) Runtime.start("opencv", "OpenCV");
* opencv.capture();
*
* sleep(1000); String photo = opencv.recordSingleFrame();
*
*
* System.out.println("Detected labels for " + photo);
*/
// set your credentials once - then comment out this line and remove the
// sensitive info
// the credentials will be saved to .myrobotlab/store
// recog.setCredentials("XXXXXXXXXXXXXXXX",
// "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
recog.loadCredentials();
List<Label> labels = null;
// labels = recog.getLabels("opencv.input.48.jpg");
labels = recog.getLabels("http://animals.sandiegozoo.org/sites/default/files/2016-08/hero_zebra_animals.jpg");
for (Label label : labels) {
System.out.println(label.getName() + ": " + label.getConfidence().toString());
}
}
Aggregations