Search in sources :

Example 1 with GetPersonTrackingResponse

use of software.amazon.awssdk.services.rekognition.model.GetPersonTrackingResponse 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

GetPersonTrackingRequest (software.amazon.awssdk.services.rekognition.model.GetPersonTrackingRequest)1 GetPersonTrackingResponse (software.amazon.awssdk.services.rekognition.model.GetPersonTrackingResponse)1 PersonDetection (software.amazon.awssdk.services.rekognition.model.PersonDetection)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)1