Search in sources :

Example 1 with Image

use of com.amazonaws.services.rekognition.model.Image 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 Image

use of com.amazonaws.services.rekognition.model.Image in project myrobotlab by MyRobotLab.

the class Rekognition method getFaces.

// FIXME make BufferedImage translations...
public List<FaceDetail> getFaces(ByteBuffer imageBytes, Integer width, Integer height) {
    DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withBytes((imageBytes))).withAttributes(Attribute.ALL);
    DetectFacesResult result = getClient().detectFaces(request);
    System.out.println("Orientation: " + result.getOrientationCorrection() + "\n");
    List<FaceDetail> faceDetails = result.getFaceDetails();
    for (FaceDetail face : faceDetails) {
        System.out.println("Face:");
        ShowBoundingBoxPositions(height, width, face.getBoundingBox(), result.getOrientationCorrection());
        AgeRange ageRange = face.getAgeRange();
        System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old.");
        System.out.println();
    }
    return faceDetails;
}
Also used : FaceDetail(com.amazonaws.services.rekognition.model.FaceDetail) AgeRange(com.amazonaws.services.rekognition.model.AgeRange) BufferedImage(java.awt.image.BufferedImage) Image(com.amazonaws.services.rekognition.model.Image) DetectFacesResult(com.amazonaws.services.rekognition.model.DetectFacesResult) DetectFacesRequest(com.amazonaws.services.rekognition.model.DetectFacesRequest)

Example 3 with Image

use of com.amazonaws.services.rekognition.model.Image in project aws-doc-sdk-examples by awsdocs.

the class SearchFaceMatchingImageCollection method main.

public static void main(String[] args) throws Exception {
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    ObjectMapper objectMapper = new ObjectMapper();
    // Get an image object from S3 bucket.
    Image image = new Image().withS3Object(new S3Object().withBucket(bucket).withName(photo));
    // Search collection for faces similar to the largest face in the image.
    SearchFacesByImageRequest searchFacesByImageRequest = new SearchFacesByImageRequest().withCollectionId(collectionId).withImage(image).withFaceMatchThreshold(70F).withMaxFaces(2);
    SearchFacesByImageResult searchFacesByImageResult = rekognitionClient.searchFacesByImage(searchFacesByImageRequest);
    System.out.println("Faces matching largest face in image from" + photo);
    List<FaceMatch> faceImageMatches = searchFacesByImageResult.getFaceMatches();
    for (FaceMatch face : faceImageMatches) {
        System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
        System.out.println();
    }
}
Also used : SearchFacesByImageRequest(com.amazonaws.services.rekognition.model.SearchFacesByImageRequest) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) Image(com.amazonaws.services.rekognition.model.Image) SearchFacesByImageResult(com.amazonaws.services.rekognition.model.SearchFacesByImageResult) FaceMatch(com.amazonaws.services.rekognition.model.FaceMatch) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with Image

use of com.amazonaws.services.rekognition.model.Image in project aws-doc-sdk-examples by awsdocs.

the class DetectFaces method main.

public static void main(String[] args) throws Exception {
    // Change bucket to your S3 bucket that contains the image file.
    // Change photo to your image file.
    String photo = "input.jpg";
    String bucket = "bucket";
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))).withAttributes(Attribute.ALL);
    try {
        DetectFacesResult result = rekognitionClient.detectFaces(request);
        List<FaceDetail> faceDetails = result.getFaceDetails();
        for (FaceDetail face : faceDetails) {
            if (request.getAttributes().contains("ALL")) {
                AgeRange ageRange = face.getAgeRange();
                System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old.");
                System.out.println("Here's the complete set of attributes:");
            } else {
                // non-default attributes have null values.
                System.out.println("Here's the default set of attributes:");
            }
            ObjectMapper objectMapper = new ObjectMapper();
            System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
        }
    } catch (AmazonRekognitionException e) {
        e.printStackTrace();
    }
}
Also used : FaceDetail(com.amazonaws.services.rekognition.model.FaceDetail) AgeRange(com.amazonaws.services.rekognition.model.AgeRange) AmazonRekognitionException(com.amazonaws.services.rekognition.model.AmazonRekognitionException) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) Image(com.amazonaws.services.rekognition.model.Image) DetectFacesResult(com.amazonaws.services.rekognition.model.DetectFacesResult) DetectFacesRequest(com.amazonaws.services.rekognition.model.DetectFacesRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with Image

use of com.amazonaws.services.rekognition.model.Image 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)

Aggregations

Image (com.amazonaws.services.rekognition.model.Image)18 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)11 S3Object (com.amazonaws.services.rekognition.model.S3Object)7 AmazonClientException (com.amazonaws.AmazonClientException)6 PredictionsException (com.amplifyframework.predictions.PredictionsException)6 ArrayList (java.util.ArrayList)6 AmazonRekognitionException (com.amazonaws.services.rekognition.model.AmazonRekognitionException)5 RectF (android.graphics.RectF)4 DetectFacesRequest (com.amazonaws.services.rekognition.model.DetectFacesRequest)4 DetectFacesResult (com.amazonaws.services.rekognition.model.DetectFacesResult)4 DetectLabelsRequest (com.amazonaws.services.rekognition.model.DetectLabelsRequest)4 DetectLabelsResult (com.amazonaws.services.rekognition.model.DetectLabelsResult)4 FaceDetail (com.amazonaws.services.rekognition.model.FaceDetail)4 BoundingBox (com.amazonaws.services.rekognition.model.BoundingBox)3 ComparedFace (com.amazonaws.services.rekognition.model.ComparedFace)3 Label (com.amazonaws.services.rekognition.model.Label)3 ModerationLabel (com.amazonaws.services.rekognition.model.ModerationLabel)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3