Search in sources :

Example 1 with Label

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;
}
Also used : AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) Label(com.amazonaws.services.rekognition.model.Label) DetectLabelsRequest(com.amazonaws.services.rekognition.model.DetectLabelsRequest) BufferedImage(java.awt.image.BufferedImage) Image(com.amazonaws.services.rekognition.model.Image) DetectLabelsResult(com.amazonaws.services.rekognition.model.DetectLabelsResult)

Example 2 with Label

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();
    }
}
Also used : Instance(com.amazonaws.services.rekognition.model.Instance) Parent(com.amazonaws.services.rekognition.model.Parent) Label(com.amazonaws.services.rekognition.model.Label) Image(com.amazonaws.services.rekognition.model.Image) DetectLabelsResult(com.amazonaws.services.rekognition.model.DetectLabelsResult) AmazonRekognitionException(com.amazonaws.services.rekognition.model.AmazonRekognitionException) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) DetectLabelsRequest(com.amazonaws.services.rekognition.model.DetectLabelsRequest) S3Object(com.amazonaws.services.rekognition.model.S3Object)

Example 3 with Label

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();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AmazonRekognitionException(com.amazonaws.services.rekognition.model.AmazonRekognitionException) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) Label(com.amazonaws.services.rekognition.model.Label) DetectLabelsRequest(com.amazonaws.services.rekognition.model.DetectLabelsRequest) Image(com.amazonaws.services.rekognition.model.Image) ByteBuffer(java.nio.ByteBuffer) File(java.io.File) DetectLabelsResult(com.amazonaws.services.rekognition.model.DetectLabelsResult) FileInputStream(java.io.FileInputStream)

Example 4 with Label

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);
}
Also used : Instance(com.amazonaws.services.rekognition.model.Instance) Parent(com.amazonaws.services.rekognition.model.Parent) GetLabelDetectionRequest(com.amazonaws.services.rekognition.model.GetLabelDetectionRequest) Label(com.amazonaws.services.rekognition.model.Label) VideoMetadata(com.amazonaws.services.rekognition.model.VideoMetadata) GetLabelDetectionResult(com.amazonaws.services.rekognition.model.GetLabelDetectionResult) LabelDetection(com.amazonaws.services.rekognition.model.LabelDetection)

Example 5 with Label

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());
    }
}
Also used : AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) Label(com.amazonaws.services.rekognition.model.Label)

Aggregations

Label (com.amazonaws.services.rekognition.model.Label)5 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)4 DetectLabelsRequest (com.amazonaws.services.rekognition.model.DetectLabelsRequest)3 DetectLabelsResult (com.amazonaws.services.rekognition.model.DetectLabelsResult)3 Image (com.amazonaws.services.rekognition.model.Image)3 AmazonRekognitionException (com.amazonaws.services.rekognition.model.AmazonRekognitionException)2 Instance (com.amazonaws.services.rekognition.model.Instance)2 Parent (com.amazonaws.services.rekognition.model.Parent)2 GetLabelDetectionRequest (com.amazonaws.services.rekognition.model.GetLabelDetectionRequest)1 GetLabelDetectionResult (com.amazonaws.services.rekognition.model.GetLabelDetectionResult)1 LabelDetection (com.amazonaws.services.rekognition.model.LabelDetection)1 S3Object (com.amazonaws.services.rekognition.model.S3Object)1 VideoMetadata (com.amazonaws.services.rekognition.model.VideoMetadata)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1