Search in sources :

Example 1 with VideoMetadata

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

Example 2 with VideoMetadata

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

the class VideoDetectSegment method getSegmentResults.

public static void getSegmentResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetSegmentDetectionResponse segDetectionResponse = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (segDetectionResponse != null)
                paginationToken = segDetectionResponse.nextToken();
            GetSegmentDetectionRequest recognitionRequest = GetSegmentDetectionRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                segDetectionResponse = rekClient.getSegmentDetection(recognitionRequest);
                status = segDetectionResponse.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
            List<VideoMetadata> videoMetaData = segDetectionResponse.videoMetadata();
            for (VideoMetadata metaData : videoMetaData) {
                System.out.println("Format: " + metaData.format());
                System.out.println("Codec: " + metaData.codec());
                System.out.println("Duration: " + metaData.durationMillis());
                System.out.println("FrameRate: " + metaData.frameRate());
                System.out.println("Job");
            }
            List<SegmentDetection> detectedSegment = segDetectionResponse.segments();
            String type = detectedSegment.get(0).type().toString();
            if (type.contains(SegmentType.TECHNICAL_CUE.toString())) {
                System.out.println("Technical Cue");
                TechnicalCueSegment segmentCue = detectedSegment.get(0).technicalCueSegment();
                System.out.println("\tType: " + segmentCue.type());
                System.out.println("\tConfidence: " + segmentCue.confidence().toString());
            }
            if (type.contains(SegmentType.SHOT.toString())) {
                System.out.println("Shot");
                ShotSegment segmentShot = detectedSegment.get(0).shotSegment();
                System.out.println("\tIndex " + segmentShot.index());
                System.out.println("\tConfidence: " + segmentShot.confidence().toString());
            }
            long seconds = detectedSegment.get(0).durationMillis();
            System.out.println("\tDuration : " + Long.toString(seconds) + " milliseconds");
            System.out.println("\tStart time code: " + detectedSegment.get(0).startTimecodeSMPTE());
            System.out.println("\tEnd time code: " + detectedSegment.get(0).endTimecodeSMPTE());
            System.out.println("\tDuration time code: " + detectedSegment.get(0).durationSMPTE());
            System.out.println();
        } while (segDetectionResponse != null && segDetectionResponse.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetSegmentDetectionResponse(software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata) SegmentDetection(software.amazon.awssdk.services.rekognition.model.SegmentDetection) TechnicalCueSegment(software.amazon.awssdk.services.rekognition.model.TechnicalCueSegment) ShotSegment(software.amazon.awssdk.services.rekognition.model.ShotSegment) GetSegmentDetectionRequest(software.amazon.awssdk.services.rekognition.model.GetSegmentDetectionRequest)

Example 3 with VideoMetadata

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

the class VideoDetect method GetResultsLabels.

// Gets the job results by calling GetLabelDetection
private static void GetResultsLabels(RekognitionClient rekClient) {
    int maxResults = 10;
    String paginationToken = null;
    GetLabelDetectionResponse labelDetectionResult = null;
    try {
        do {
            if (labelDetectionResult != null)
                paginationToken = labelDetectionResult.nextToken();
            GetLabelDetectionRequest labelDetectionRequest = GetLabelDetectionRequest.builder().jobId(startJobId).sortBy(LabelDetectionSortBy.TIMESTAMP).maxResults(maxResults).nextToken(paginationToken).build();
            labelDetectionResult = rekClient.getLabelDetection(labelDetectionRequest);
            VideoMetadata videoMetaData = labelDetectionResult.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());
            List<LabelDetection> detectedLabels = labelDetectionResult.labels();
            for (LabelDetection detectedLabel : detectedLabels) {
                long seconds = detectedLabel.timestamp();
                Label label = detectedLabel.label();
                System.out.println("Millisecond: " + Long.toString(seconds) + " ");
                System.out.println("   Label:" + label.name());
                System.out.println("   Confidence:" + detectedLabel.label().confidence().toString());
                List<Instance> instances = label.instances();
                System.out.println("   Instances of " + label.name());
                if (instances.isEmpty()) {
                    System.out.println("        " + "None");
                } else {
                    for (Instance instance : instances) {
                        System.out.println("        Confidence: " + instance.confidence().toString());
                        System.out.println("        Bounding box: " + instance.boundingBox().toString());
                    }
                }
                System.out.println("   Parent labels for " + label.name() + ":");
                List<Parent> parents = label.parents();
                if (parents.isEmpty()) {
                    System.out.println("        None");
                } else {
                    for (Parent parent : parents) {
                        System.out.println("   " + parent.name());
                    }
                }
                System.out.println();
            }
        } while (labelDetectionResult != null && labelDetectionResult.nextToken() != null);
    } catch (RekognitionException e) {
        e.getMessage();
        System.exit(1);
    }
}
Also used : Instance(software.amazon.awssdk.services.rekognition.model.Instance) Parent(software.amazon.awssdk.services.rekognition.model.Parent) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) GetLabelDetectionRequest(software.amazon.awssdk.services.rekognition.model.GetLabelDetectionRequest) Label(software.amazon.awssdk.services.rekognition.model.Label) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata) GetLabelDetectionResponse(software.amazon.awssdk.services.rekognition.model.GetLabelDetectionResponse) LabelDetection(software.amazon.awssdk.services.rekognition.model.LabelDetection)

Example 4 with VideoMetadata

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

the class VideoDetectInappropriate method GetModResults.

public static void GetModResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetContentModerationResponse modDetectionResponse = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (modDetectionResponse != null)
                paginationToken = modDetectionResponse.nextToken();
            GetContentModerationRequest modRequest = GetContentModerationRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                modDetectionResponse = rekClient.getContentModeration(modRequest);
                status = modDetectionResponse.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 = modDetectionResponse.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<ContentModerationDetection> mods = modDetectionResponse.moderationLabels();
            for (ContentModerationDetection mod : mods) {
                long seconds = mod.timestamp() / 1000;
                System.out.print("Mod label: " + seconds + " ");
                System.out.println(mod.moderationLabel().toString());
                System.out.println();
            }
        } while (modDetectionResponse != null && modDetectionResponse.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetContentModerationResponse(software.amazon.awssdk.services.rekognition.model.GetContentModerationResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) GetContentModerationRequest(software.amazon.awssdk.services.rekognition.model.GetContentModerationRequest) ContentModerationDetection(software.amazon.awssdk.services.rekognition.model.ContentModerationDetection) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata)

Example 5 with VideoMetadata

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

the class VideoDetectText method GetTextResults.

public static void GetTextResults(RekognitionClient rekClient) {
    try {
        String paginationToken = null;
        GetTextDetectionResponse textDetectionResponse = null;
        Boolean finished = false;
        String status = "";
        int yy = 0;
        do {
            if (textDetectionResponse != null)
                paginationToken = textDetectionResponse.nextToken();
            GetTextDetectionRequest recognitionRequest = GetTextDetectionRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
            // Wait until the job succeeds
            while (!finished) {
                textDetectionResponse = rekClient.getTextDetection(recognitionRequest);
                status = textDetectionResponse.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 = textDetectionResponse.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<TextDetectionResult> labels = textDetectionResponse.textDetections();
            for (TextDetectionResult detectedText : labels) {
                System.out.println("Confidence: " + detectedText.textDetection().confidence().toString());
                System.out.println("Id : " + detectedText.textDetection().id());
                System.out.println("Parent Id: " + detectedText.textDetection().parentId());
                System.out.println("Type: " + detectedText.textDetection().type());
                System.out.println("Text: " + detectedText.textDetection().detectedText());
                System.out.println();
            }
        } while (textDetectionResponse != null && textDetectionResponse.nextToken() != null);
    } catch (RekognitionException | InterruptedException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetTextDetectionRequest(software.amazon.awssdk.services.rekognition.model.GetTextDetectionRequest) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) TextDetectionResult(software.amazon.awssdk.services.rekognition.model.TextDetectionResult) VideoMetadata(software.amazon.awssdk.services.rekognition.model.VideoMetadata) GetTextDetectionResponse(software.amazon.awssdk.services.rekognition.model.GetTextDetectionResponse)

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