Search in sources :

Example 1 with CelebrityDetail

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

the class VideoCelebrityDetection method GetCelebrityDetectionResults.

public static void GetCelebrityDetectionResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetCelebrityRecognitionResponse recognitionResponse = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (recognitionResponse != null)
                paginationToken = recognitionResponse.nextToken();
            GetCelebrityRecognitionRequest recognitionRequest = GetCelebrityRecognitionRequest.builder().jobId(startJobId).nextToken(paginationToken).sortBy(CelebrityRecognitionSortBy.TIMESTAMP).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                recognitionResponse = rekClient.getCelebrityRecognition(recognitionRequest);
                status = recognitionResponse.jobStatusAsString();
                if (status.compareTo("SUCCEEDED") == 0)
                    finished = true;
                else {
                    System.out.println(yy + " status is: " + status);
                    Thread.sleep(1000);
                }
                yy++;
            }
            finished = false;
            // Proceed when the job is done - otherwise VideoMetadata is null
            VideoMetadata videoMetaData = recognitionResponse.videoMetadata();
            System.out.println("Format: " + videoMetaData.format());
            System.out.println("Codec: " + videoMetaData.codec());
            System.out.println("Duration: " + videoMetaData.durationMillis());
            System.out.println("FrameRate: " + videoMetaData.frameRate());
            System.out.println("Job");
            List<CelebrityRecognition> celebs = recognitionResponse.celebrities();
            for (CelebrityRecognition celeb : celebs) {
                long seconds = celeb.timestamp() / 1000;
                System.out.print("Sec: " + Long.toString(seconds) + " ");
                CelebrityDetail details = celeb.celebrity();
                System.out.println("Name: " + details.name());
                System.out.println("Id: " + details.id());
                System.out.println();
            }
        } while (recognitionResponse != null && recognitionResponse.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) GetCelebrityRecognitionResponse(software.amazon.awssdk.services.rekognition.model.GetCelebrityRecognitionResponse) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata) CelebrityRecognition(software.amazon.awssdk.services.rekognition.model.CelebrityRecognition) CelebrityDetail(software.amazon.awssdk.services.rekognition.model.CelebrityDetail) GetCelebrityRecognitionRequest(software.amazon.awssdk.services.rekognition.model.GetCelebrityRecognitionRequest)

Aggregations

CelebrityDetail (software.amazon.awssdk.services.rekognition.model.CelebrityDetail)1 CelebrityRecognition (software.amazon.awssdk.services.rekognition.model.CelebrityRecognition)1 GetCelebrityRecognitionRequest (software.amazon.awssdk.services.rekognition.model.GetCelebrityRecognitionRequest)1 GetCelebrityRecognitionResponse (software.amazon.awssdk.services.rekognition.model.GetCelebrityRecognitionResponse)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)1