use of software.amazon.awssdk.services.rekognition.model.RekognitionException in project aws-doc-sdk-examples by awsdocs.
the class ListFacesInCollection method listFacesCollection.
// snippet-start:[rekognition.java2.list_faces_collection.main]
public static void listFacesCollection(RekognitionClient rekClient, String collectionId) {
try {
ListFacesRequest facesRequest = ListFacesRequest.builder().collectionId(collectionId).maxResults(10).build();
ListFacesResponse facesResponse = rekClient.listFaces(facesRequest);
// For each face in the collection, print out the confidence level and face id value.
List<Face> faces = facesResponse.faces();
for (Face face : faces) {
System.out.println("Confidence level there is a face: " + face.confidence());
System.out.println("The face Id value is " + face.faceId());
}
} catch (RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.rekognition.model.RekognitionException 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.RekognitionException in project aws-doc-sdk-examples by awsdocs.
the class VideoCelebrityDetection method StartCelebrityDetection.
// snippet-start:[rekognition.java2.recognize_video_celebrity.main]
public static void StartCelebrityDetection(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();
StartCelebrityRecognitionRequest recognitionRequest = StartCelebrityRecognitionRequest.builder().jobTag("Celebrities").notificationChannel(channel).video(vidOb).build();
StartCelebrityRecognitionResponse startCelebrityRecognitionResult = rekClient.startCelebrityRecognition(recognitionRequest);
startJobId = startCelebrityRecognitionResult.jobId();
} catch (RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.rekognition.model.RekognitionException 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.RekognitionException in project aws-doc-sdk-examples by awsdocs.
the class DetectLabels method detectImageLabels.
// snippet-start:[rekognition.java2.detect_labels.main]
public static void detectImageLabels(RekognitionClient rekClient, String sourceImage) {
try {
InputStream sourceStream = new URL("https://images.unsplash.com/photo-1557456170-0cf4f4d0d362?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bGFrZXxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80").openStream();
// InputStream sourceStream = new FileInputStream(sourceImage);
SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
// Create an Image object for the source image.
Image souImage = Image.builder().bytes(sourceBytes).build();
DetectLabelsRequest detectLabelsRequest = DetectLabelsRequest.builder().image(souImage).maxLabels(10).build();
DetectLabelsResponse labelsResponse = rekClient.detectLabels(detectLabelsRequest);
List<Label> labels = labelsResponse.labels();
System.out.println("Detected labels for the given photo");
for (Label label : labels) {
System.out.println(label.name() + ": " + label.confidence().toString());
}
} catch (RekognitionException | FileNotFoundException | MalformedURLException e) {
System.out.println(e.getMessage());
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations