Search in sources :

Example 6 with VideoMetadata

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

the class VideoDetect method GetResultsLabels.

// Gets the results of labels detection by calling GetLabelDetection. Label
// detection is started by a call to StartLabelDetection.
private static void GetResultsLabels() throws Exception {
    int maxResults = 10;
    String paginationToken = null;
    GetLabelDetectionResult labelDetectionResult = null;
    do {
        if (labelDetectionResult != null) {
            paginationToken = labelDetectionResult.getNextToken();
        }
        GetLabelDetectionRequest labelDetectionRequest = new GetLabelDetectionRequest().withJobId(startJobId).withSortBy(LabelDetectionSortBy.TIMESTAMP).withMaxResults(maxResults).withNextToken(paginationToken);
        labelDetectionResult = rek.getLabelDetection(labelDetectionRequest);
        VideoMetadata videoMetaData = labelDetectionResult.getVideoMetadata();
        System.out.println("Format: " + videoMetaData.getFormat());
        System.out.println("Codec: " + videoMetaData.getCodec());
        System.out.println("Duration: " + videoMetaData.getDurationMillis());
        System.out.println("FrameRate: " + videoMetaData.getFrameRate());
        // Show labels, confidence and detection times
        List<LabelDetection> detectedLabels = labelDetectionResult.getLabels();
        for (LabelDetection detectedLabel : detectedLabels) {
            long seconds = detectedLabel.getTimestamp();
            Label label = detectedLabel.getLabel();
            System.out.println("Millisecond: " + Long.toString(seconds) + " ");
            System.out.println("   Label:" + label.getName());
            System.out.println("   Confidence:" + detectedLabel.getLabel().getConfidence().toString());
            List<Instance> instances = label.getInstances();
            System.out.println("   Instances of " + label.getName());
            if (instances.isEmpty()) {
                System.out.println("        " + "None");
            } else {
                for (Instance instance : instances) {
                    System.out.println("        Confidence: " + instance.getConfidence().toString());
                    System.out.println("        Bounding box: " + instance.getBoundingBox().toString());
                }
            }
            System.out.println("   Parent labels for " + label.getName() + ":");
            List<Parent> parents = label.getParents();
            if (parents.isEmpty()) {
                System.out.println("        None");
            } else {
                for (Parent parent : parents) {
                    System.out.println("        " + parent.getName());
                }
            }
            System.out.println();
        }
    } while (labelDetectionResult != null && labelDetectionResult.getNextToken() != null);
}
Also used : Instance(com.amazonaws.services.rekognition.model.Instance) Parent(com.amazonaws.services.rekognition.model.Parent) GetLabelDetectionRequest(com.amazonaws.services.rekognition.model.GetLabelDetectionRequest) Label(com.amazonaws.services.rekognition.model.Label) VideoMetadata(com.amazonaws.services.rekognition.model.VideoMetadata) GetLabelDetectionResult(com.amazonaws.services.rekognition.model.GetLabelDetectionResult) LabelDetection(com.amazonaws.services.rekognition.model.LabelDetection)

Example 7 with VideoMetadata

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

the class VideoDetect method GetResultsFaces.

// Gets the results of face detection by calling GetFaceDetection. Face
// detection is started by calling StartFaceDetection.
private static void GetResultsFaces() throws Exception {
    int maxResults = 10;
    String paginationToken = null;
    GetFaceDetectionResult faceDetectionResult = null;
    do {
        if (faceDetectionResult != null) {
            paginationToken = faceDetectionResult.getNextToken();
        }
        faceDetectionResult = rek.getFaceDetection(new GetFaceDetectionRequest().withJobId(startJobId).withNextToken(paginationToken).withMaxResults(maxResults));
        VideoMetadata videoMetaData = faceDetectionResult.getVideoMetadata();
        System.out.println("Format: " + videoMetaData.getFormat());
        System.out.println("Codec: " + videoMetaData.getCodec());
        System.out.println("Duration: " + videoMetaData.getDurationMillis());
        System.out.println("FrameRate: " + videoMetaData.getFrameRate());
        // Show faces, confidence and detection times
        List<FaceDetection> faces = faceDetectionResult.getFaces();
        for (FaceDetection face : faces) {
            long seconds = face.getTimestamp() / 1000;
            System.out.print("Sec: " + Long.toString(seconds) + " ");
            System.out.println(face.getFace().toString());
            System.out.println();
        }
    } while (faceDetectionResult != null && faceDetectionResult.getNextToken() != null);
}
Also used : FaceDetection(com.amazonaws.services.rekognition.model.FaceDetection) GetFaceDetectionResult(com.amazonaws.services.rekognition.model.GetFaceDetectionResult) GetFaceDetectionRequest(com.amazonaws.services.rekognition.model.GetFaceDetectionRequest) VideoMetadata(com.amazonaws.services.rekognition.model.VideoMetadata)

Aggregations

VideoMetadata (com.amazonaws.services.rekognition.model.VideoMetadata)7 GetLabelDetectionRequest (com.amazonaws.services.rekognition.model.GetLabelDetectionRequest)2 GetLabelDetectionResult (com.amazonaws.services.rekognition.model.GetLabelDetectionResult)2 LabelDetection (com.amazonaws.services.rekognition.model.LabelDetection)2 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)1 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 CelebrityDetail (com.amazonaws.services.rekognition.model.CelebrityDetail)1 CelebrityRecognition (com.amazonaws.services.rekognition.model.CelebrityRecognition)1 ContentModerationDetection (com.amazonaws.services.rekognition.model.ContentModerationDetection)1 Face (com.amazonaws.services.rekognition.model.Face)1 FaceDetection (com.amazonaws.services.rekognition.model.FaceDetection)1 FaceMatch (com.amazonaws.services.rekognition.model.FaceMatch)1 GetCelebrityRecognitionRequest (com.amazonaws.services.rekognition.model.GetCelebrityRecognitionRequest)1 GetCelebrityRecognitionResult (com.amazonaws.services.rekognition.model.GetCelebrityRecognitionResult)1 GetContentModerationRequest (com.amazonaws.services.rekognition.model.GetContentModerationRequest)1 GetContentModerationResult (com.amazonaws.services.rekognition.model.GetContentModerationResult)1 GetFaceDetectionRequest (com.amazonaws.services.rekognition.model.GetFaceDetectionRequest)1 GetFaceDetectionResult (com.amazonaws.services.rekognition.model.GetFaceDetectionResult)1 GetFaceSearchRequest (com.amazonaws.services.rekognition.model.GetFaceSearchRequest)1 GetFaceSearchResult (com.amazonaws.services.rekognition.model.GetFaceSearchResult)1