Search in sources :

Example 1 with S3Object

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

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

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

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

the class DetectText method main.

public static void main(String[] args) throws Exception {
    // Change the value of bucket to the S3 bucket that contains your image file.
    // Change the value of photo to your image file name.
    String photo = "inputtext.jpg";
    String bucket = "bucket";
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    DetectTextRequest request = new DetectTextRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)));
    try {
        DetectTextResult result = rekognitionClient.detectText(request);
        List<TextDetection> textDetections = result.getTextDetections();
        System.out.println("Detected lines and words for " + photo);
        for (TextDetection text : textDetections) {
            System.out.println("Detected: " + text.getDetectedText());
            System.out.println("Confidence: " + text.getConfidence().toString());
            System.out.println("Id : " + text.getId());
            System.out.println("Parent Id: " + text.getParentId());
            System.out.println("Type: " + text.getType());
            System.out.println();
        }
    } catch (AmazonRekognitionException e) {
        e.printStackTrace();
    }
}
Also used : TextDetection(com.amazonaws.services.rekognition.model.TextDetection) DetectTextRequest(com.amazonaws.services.rekognition.model.DetectTextRequest) 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) DetectTextResult(com.amazonaws.services.rekognition.model.DetectTextResult)

Example 5 with S3Object

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

the class DisplayFaces method main.

public static void main(String[] arg) throws Exception {
    // Change the value of bucket to the S3 bucket that contains your image file.
    // Change the value of photo to your image file name.
    String photo = "input.png";
    String bucket = "bucket";
    int height = 0;
    int width = 0;
    // Get the image from an S3 Bucket
    AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
    com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, photo);
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    BufferedImage image = ImageIO.read(inputStream);
    DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)));
    width = image.getWidth();
    height = image.getHeight();
    // Call DetectFaces
    AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient();
    DetectFacesResult result = amazonRekognition.detectFaces(request);
    // Show the bounding box info for each face.
    List<FaceDetail> faceDetails = result.getFaceDetails();
    for (FaceDetail face : faceDetails) {
        BoundingBox box = face.getBoundingBox();
        float left = width * box.getLeft();
        float top = height * box.getTop();
        System.out.println("Face:");
        System.out.println("Left: " + String.valueOf((int) left));
        System.out.println("Top: " + String.valueOf((int) top));
        System.out.println("Face Width: " + String.valueOf((int) (width * box.getWidth())));
        System.out.println("Face Height: " + String.valueOf((int) (height * box.getHeight())));
        System.out.println();
    }
    // Create frame and panel.
    JFrame frame = new JFrame("RotateImage");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DisplayFaces panel = new DisplayFaces(result, image);
    panel.setPreferredSize(new Dimension(image.getWidth() / scale, image.getHeight() / scale));
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) BufferedImage(java.awt.image.BufferedImage) Image(com.amazonaws.services.rekognition.model.Image) BufferedImage(java.awt.image.BufferedImage) FaceDetail(com.amazonaws.services.rekognition.model.FaceDetail) BoundingBox(com.amazonaws.services.rekognition.model.BoundingBox) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) DetectFacesResult(com.amazonaws.services.rekognition.model.DetectFacesResult) DetectFacesRequest(com.amazonaws.services.rekognition.model.DetectFacesRequest)

Aggregations

S3Object (com.amazonaws.services.rekognition.model.S3Object)13 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)7 Image (com.amazonaws.services.rekognition.model.Image)7 Video (com.amazonaws.services.rekognition.model.Video)6 AmazonRekognitionException (com.amazonaws.services.rekognition.model.AmazonRekognitionException)4 DetectFacesRequest (com.amazonaws.services.rekognition.model.DetectFacesRequest)2 DetectFacesResult (com.amazonaws.services.rekognition.model.DetectFacesResult)2 FaceDetail (com.amazonaws.services.rekognition.model.FaceDetail)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AgeRange (com.amazonaws.services.rekognition.model.AgeRange)1 BoundingBox (com.amazonaws.services.rekognition.model.BoundingBox)1 DetectLabelsRequest (com.amazonaws.services.rekognition.model.DetectLabelsRequest)1 DetectLabelsResult (com.amazonaws.services.rekognition.model.DetectLabelsResult)1 DetectModerationLabelsRequest (com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest)1 DetectModerationLabelsResult (com.amazonaws.services.rekognition.model.DetectModerationLabelsResult)1 DetectTextRequest (com.amazonaws.services.rekognition.model.DetectTextRequest)1 DetectTextResult (com.amazonaws.services.rekognition.model.DetectTextResult)1 FaceMatch (com.amazonaws.services.rekognition.model.FaceMatch)1 FaceRecord (com.amazonaws.services.rekognition.model.FaceRecord)1 IndexFacesRequest (com.amazonaws.services.rekognition.model.IndexFacesRequest)1