Search in sources :

Example 26 with RekognitionException

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

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

Example 28 with RekognitionException

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

the class DescribeCollection method describeColl.

// snippet-start:[rekognition.java2.describe_collection.main]
public static void describeColl(RekognitionClient rekClient, String collectionName) {
    try {
        DescribeCollectionRequest describeCollectionRequest = DescribeCollectionRequest.builder().collectionId(collectionName).build();
        DescribeCollectionResponse describeCollectionResponse = rekClient.describeCollection(describeCollectionRequest);
        System.out.println("Collection Arn : " + describeCollectionResponse.collectionARN());
        System.out.println("Created : " + describeCollectionResponse.creationTimestamp().toString());
    } catch (RekognitionException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : DescribeCollectionRequest(software.amazon.awssdk.services.rekognition.model.DescribeCollectionRequest) DescribeCollectionResponse(software.amazon.awssdk.services.rekognition.model.DescribeCollectionResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException)

Example 29 with RekognitionException

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

Example 30 with RekognitionException

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

the class VideoPersonDetection method startPersonLabels.

// snippet-start:[rekognition.java2.recognize_video_person.main]
public static void startPersonLabels(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();
        StartPersonTrackingRequest personTrackingRequest = StartPersonTrackingRequest.builder().jobTag("DetectingLabels").video(vidOb).notificationChannel(channel).build();
        StartPersonTrackingResponse labelDetectionResponse = rekClient.startPersonTracking(personTrackingRequest);
        startJobId = labelDetectionResponse.jobId();
    } catch (RekognitionException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) Video(software.amazon.awssdk.services.rekognition.model.Video) StartPersonTrackingRequest(software.amazon.awssdk.services.rekognition.model.StartPersonTrackingRequest) S3Object(software.amazon.awssdk.services.rekognition.model.S3Object) StartPersonTrackingResponse(software.amazon.awssdk.services.rekognition.model.StartPersonTrackingResponse)

Aggregations

RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)33 Image (software.amazon.awssdk.services.rekognition.model.Image)12 SdkBytes (software.amazon.awssdk.core.SdkBytes)10 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 InputStream (java.io.InputStream)8 S3Object (software.amazon.awssdk.services.rekognition.model.S3Object)8 Video (software.amazon.awssdk.services.rekognition.model.Video)6 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)6 File (java.io.File)2 Celebrity (software.amazon.awssdk.services.rekognition.model.Celebrity)2 ComparedFace (software.amazon.awssdk.services.rekognition.model.ComparedFace)2 DetectLabelsRequest (software.amazon.awssdk.services.rekognition.model.DetectLabelsRequest)2 DetectLabelsResponse (software.amazon.awssdk.services.rekognition.model.DetectLabelsResponse)2 FaceMatch (software.amazon.awssdk.services.rekognition.model.FaceMatch)2 Label (software.amazon.awssdk.services.rekognition.model.Label)2 RecognizeCelebritiesRequest (software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesRequest)2 RecognizeCelebritiesResponse (software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesResponse)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1