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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations