Search in sources :

Example 6 with VideoMetadata

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

the class VideoPersonDetection method GetPersonDetectionResults.

public static void GetPersonDetectionResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetPersonTrackingResponse personTrackingResult = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (personTrackingResult != null)
                paginationToken = personTrackingResult.nextToken();
            GetPersonTrackingRequest recognitionRequest = GetPersonTrackingRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                personTrackingResult = rekClient.getPersonTracking(recognitionRequest);
                status = personTrackingResult.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 = personTrackingResult.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<PersonDetection> detectedPersons = personTrackingResult.persons();
            for (PersonDetection detectedPerson : detectedPersons) {
                long seconds = detectedPerson.timestamp() / 1000;
                System.out.print("Sec: " + seconds + " ");
                System.out.println("Person Identifier: " + detectedPerson.person().index());
                System.out.println();
            }
        } while (personTrackingResult != null && personTrackingResult.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetPersonTrackingResponse(software.amazon.awssdk.services.rekognition.model.GetPersonTrackingResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) GetPersonTrackingRequest(software.amazon.awssdk.services.rekognition.model.GetPersonTrackingRequest) PersonDetection(software.amazon.awssdk.services.rekognition.model.PersonDetection) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata)

Aggregations

RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)6 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)6 CelebrityDetail (software.amazon.awssdk.services.rekognition.model.CelebrityDetail)1 CelebrityRecognition (software.amazon.awssdk.services.rekognition.model.CelebrityRecognition)1 ContentModerationDetection (software.amazon.awssdk.services.rekognition.model.ContentModerationDetection)1 GetCelebrityRecognitionRequest (software.amazon.awssdk.services.rekognition.model.GetCelebrityRecognitionRequest)1 GetCelebrityRecognitionResponse (software.amazon.awssdk.services.rekognition.model.GetCelebrityRecognitionResponse)1 GetContentModerationRequest (software.amazon.awssdk.services.rekognition.model.GetContentModerationRequest)1 GetContentModerationResponse (software.amazon.awssdk.services.rekognition.model.GetContentModerationResponse)1 GetLabelDetectionRequest (software.amazon.awssdk.services.rekognition.model.GetLabelDetectionRequest)1 GetLabelDetectionResponse (software.amazon.awssdk.services.rekognition.model.GetLabelDetectionResponse)1 GetPersonTrackingRequest (software.amazon.awssdk.services.rekognition.model.GetPersonTrackingRequest)1 GetPersonTrackingResponse (software.amazon.awssdk.services.rekognition.model.GetPersonTrackingResponse)1 GetSegmentDetectionRequest (software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionRequest)1 GetSegmentDetectionResponse (software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionResponse)1 GetTextDetectionRequest (software.amazon.awssdk.services.rekognition.model.GetTextDetectionRequest)1 GetTextDetectionResponse (software.amazon.awssdk.services.rekognition.model.GetTextDetectionResponse)1 Instance (software.amazon.awssdk.services.rekognition.model.Instance)1 Label (software.amazon.awssdk.services.rekognition.model.Label)1 LabelDetection (software.amazon.awssdk.services.rekognition.model.LabelDetection)1