Search in sources :

Example 1 with Celebrity

use of software.amazon.awssdk.services.rekognition.model.Celebrity in project aws-doc-sdk-examples by awsdocs.

the class RecognizeCelebrities method recognizeAllCelebrities.

// snippet-start:[rekognition.java2.recognize_celebs.main]
public static void recognizeAllCelebrities(RekognitionClient rekClient, String sourceImage) {
    try {
        InputStream sourceStream = new FileInputStream(sourceImage);
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        Image souImage = Image.builder().bytes(sourceBytes).build();
        RecognizeCelebritiesRequest request = RecognizeCelebritiesRequest.builder().image(souImage).build();
        RecognizeCelebritiesResponse result = rekClient.recognizeCelebrities(request);
        List<Celebrity> celebs = result.celebrityFaces();
        System.out.println(celebs.size() + " celebrity(s) were recognized.\n");
        for (Celebrity celebrity : celebs) {
            System.out.println("Celebrity recognized: " + celebrity.name());
            System.out.println("Celebrity ID: " + celebrity.id());
            System.out.println("Further information (if available):");
            for (String url : celebrity.urls()) {
                System.out.println(url);
            }
            System.out.println();
        }
        System.out.println(result.unrecognizedFaces().size() + " face(s) were unrecognized.");
    } catch (RekognitionException | FileNotFoundException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : RecognizeCelebritiesResponse(software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) RecognizeCelebritiesRequest(software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesRequest) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Celebrity(software.amazon.awssdk.services.rekognition.model.Celebrity) FileNotFoundException(java.io.FileNotFoundException) Image(software.amazon.awssdk.services.rekognition.model.Image) FileInputStream(java.io.FileInputStream)

Example 2 with Celebrity

use of software.amazon.awssdk.services.rekognition.model.Celebrity in project aws-doc-sdk-examples by awsdocs.

the class RotateImage method recognizeAllCelebrities.

// snippet-start:[rekognition.java2.recognize_image_orientation.main]
public static void recognizeAllCelebrities(RekognitionClient rekClient, String sourceImage) {
    try {
        BufferedImage image = null;
        InputStream sourceStream = new FileInputStream(sourceImage);
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        image = ImageIO.read(sourceBytes.asInputStream());
        int height = image.getHeight();
        int width = image.getWidth();
        Image souImage = Image.builder().bytes(sourceBytes).build();
        RecognizeCelebritiesRequest request = RecognizeCelebritiesRequest.builder().image(souImage).build();
        RecognizeCelebritiesResponse result = rekClient.recognizeCelebrities(request);
        List<Celebrity> celebs = result.celebrityFaces();
        System.out.println(celebs.size() + " celebrity(s) were recognized.\n");
        for (Celebrity celebrity : celebs) {
            System.out.println("Celebrity recognized: " + celebrity.name());
            System.out.println("Celebrity ID: " + celebrity.id());
            ComparedFace face = celebrity.face();
            ShowBoundingBoxPositions(height, width, face.boundingBox(), result.orientationCorrectionAsString());
        }
    } catch (RekognitionException | FileNotFoundException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) BufferedImage(java.awt.image.BufferedImage) Image(software.amazon.awssdk.services.rekognition.model.Image) ComparedFace(software.amazon.awssdk.services.rekognition.model.ComparedFace) BufferedImage(java.awt.image.BufferedImage) RecognizeCelebritiesResponse(software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) RecognizeCelebritiesRequest(software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesRequest) Celebrity(software.amazon.awssdk.services.rekognition.model.Celebrity)

Aggregations

SdkBytes (software.amazon.awssdk.core.SdkBytes)2 Celebrity (software.amazon.awssdk.services.rekognition.model.Celebrity)2 Image (software.amazon.awssdk.services.rekognition.model.Image)2 RecognizeCelebritiesRequest (software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesRequest)2 RecognizeCelebritiesResponse (software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesResponse)2 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)2 BufferedImage (java.awt.image.BufferedImage)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ComparedFace (software.amazon.awssdk.services.rekognition.model.ComparedFace)1