Search in sources :

Example 1 with Celebrity

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

the class RecognizeCelebrities method main.

public static void main(String[] args) {
    // Change photo to the path and filename of your image.
    String photo = "moviestars.jpg";
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    ByteBuffer imageBytes = null;
    try (InputStream inputStream = new FileInputStream(new File(photo))) {
        imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
    } catch (Exception e) {
        System.out.println("Failed to load file " + photo);
        System.exit(1);
    }
    RecognizeCelebritiesRequest request = new RecognizeCelebritiesRequest().withImage(new Image().withBytes(imageBytes));
    System.out.println("Looking for celebrities in image " + photo + "\n");
    RecognizeCelebritiesResult result = rekognitionClient.recognizeCelebrities(request);
    // Display recognized celebrity information
    List<Celebrity> celebs = result.getCelebrityFaces();
    System.out.println(celebs.size() + " celebrity(s) were recognized.\n");
    for (Celebrity celebrity : celebs) {
        System.out.println("Celebrity recognized: " + celebrity.getName());
        System.out.println("Celebrity ID: " + celebrity.getId());
        BoundingBox boundingBox = celebrity.getFace().getBoundingBox();
        System.out.println("position: " + boundingBox.getLeft().toString() + " " + boundingBox.getTop().toString());
        System.out.println("Further information (if available):");
        for (String url : celebrity.getUrls()) {
            System.out.println(url);
        }
        System.out.println();
    }
    System.out.println(result.getUnrecognizedFaces().size() + " face(s) were unrecognized.");
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Image(com.amazonaws.services.rekognition.model.Image) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) RecognizeCelebritiesResult(com.amazonaws.services.rekognition.model.RecognizeCelebritiesResult) RecognizeCelebritiesRequest(com.amazonaws.services.rekognition.model.RecognizeCelebritiesRequest) Celebrity(com.amazonaws.services.rekognition.model.Celebrity) BoundingBox(com.amazonaws.services.rekognition.model.BoundingBox) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) File(java.io.File)

Aggregations

AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 BoundingBox (com.amazonaws.services.rekognition.model.BoundingBox)1 Celebrity (com.amazonaws.services.rekognition.model.Celebrity)1 Image (com.amazonaws.services.rekognition.model.Image)1 RecognizeCelebritiesRequest (com.amazonaws.services.rekognition.model.RecognizeCelebritiesRequest)1 RecognizeCelebritiesResult (com.amazonaws.services.rekognition.model.RecognizeCelebritiesResult)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1