Search in sources :

Example 1 with GetLabelDetectionResponse

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

the class VideoDetect method startLabels.

// snippet-start:[rekognition.java2.recognize_video_detect.main]
public static void startLabels(RekognitionClient rekClient, NotificationChannel channel, String bucket, String video) {
    try {
        S3Object s3Obj = S3Object.builder().bucket(bucket).name(video).build();
        Video vidOb = Video.builder().s3Object(s3Obj).build();
        StartLabelDetectionRequest labelDetectionRequest = StartLabelDetectionRequest.builder().jobTag("DetectingLabels").notificationChannel(channel).video(vidOb).minConfidence(50F).build();
        StartLabelDetectionResponse labelDetectionResponse = rekClient.startLabelDetection(labelDetectionRequest);
        startJobId = labelDetectionResponse.jobId();
        boolean ans = true;
        String status = "";
        int yy = 0;
        while (ans) {
            GetLabelDetectionRequest detectionRequest = GetLabelDetectionRequest.builder().jobId(startJobId).maxResults(10).build();
            GetLabelDetectionResponse result = rekClient.getLabelDetection(detectionRequest);
            status = result.jobStatusAsString();
            if (status.compareTo("SUCCEEDED") == 0)
                ans = false;
            else
                System.out.println(yy + " status is: " + status);
            Thread.sleep(1000);
            yy++;
        }
        System.out.println(startJobId + " status is: " + status);
    } catch (RekognitionException | InterruptedException e) {
        e.getMessage();
        System.exit(1);
    }
}
Also used : GetLabelDetectionResponse(software.amazon.awssdk.services.rekognition.model.GetLabelDetectionResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) Video(software.amazon.awssdk.services.rekognition.model.Video) GetLabelDetectionRequest(software.amazon.awssdk.services.rekognition.model.GetLabelDetectionRequest) StartLabelDetectionRequest(software.amazon.awssdk.services.rekognition.model.StartLabelDetectionRequest) S3Object(software.amazon.awssdk.services.rekognition.model.S3Object) StartLabelDetectionResponse(software.amazon.awssdk.services.rekognition.model.StartLabelDetectionResponse)

Example 2 with GetLabelDetectionResponse

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

Aggregations

GetLabelDetectionRequest (software.amazon.awssdk.services.rekognition.model.GetLabelDetectionRequest)2 GetLabelDetectionResponse (software.amazon.awssdk.services.rekognition.model.GetLabelDetectionResponse)2 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)2 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 Parent (software.amazon.awssdk.services.rekognition.model.Parent)1 S3Object (software.amazon.awssdk.services.rekognition.model.S3Object)1 StartLabelDetectionRequest (software.amazon.awssdk.services.rekognition.model.StartLabelDetectionRequest)1 StartLabelDetectionResponse (software.amazon.awssdk.services.rekognition.model.StartLabelDetectionResponse)1 Video (software.amazon.awssdk.services.rekognition.model.Video)1 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)1