use of software.amazon.awssdk.services.rekognition.RekognitionClient in project aws-doc-sdk-examples by awsdocs.
the class CreateCollection method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage: " + " <collectionName> \n\n" + "Where:\n" + " collectionName - the name of the collection. \n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String collectionId = args[0];
Region region = Region.US_EAST_1;
RekognitionClient rekClient = RekognitionClient.builder().region(region).build();
System.out.println("Creating collection: " + collectionId);
createMyCollection(rekClient, collectionId);
rekClient.close();
}
use of software.amazon.awssdk.services.rekognition.RekognitionClient in project aws-doc-sdk-examples by awsdocs.
the class AnalyzePhotos method detectLabels.
// Returns a list of GearItem objects that contains PPE information.
public ArrayList<GearItem> detectLabels(byte[] bytes, String key) {
Region region = Region.US_EAST_2;
RekognitionClient rekClient = RekognitionClient.builder().region(region).build();
ArrayList<GearItem> gearList = new ArrayList<>();
try {
SdkBytes sourceBytes = SdkBytes.fromByteArray(bytes);
// Create an Image object for the source image.
Image souImage = Image.builder().bytes(sourceBytes).build();
ProtectiveEquipmentSummarizationAttributes summarizationAttributes = ProtectiveEquipmentSummarizationAttributes.builder().minConfidence(80F).requiredEquipmentTypesWithStrings("FACE_COVER", "HAND_COVER", "HEAD_COVER").build();
DetectProtectiveEquipmentRequest request = DetectProtectiveEquipmentRequest.builder().image(souImage).summarizationAttributes(summarizationAttributes).build();
DetectProtectiveEquipmentResponse result = rekClient.detectProtectiveEquipment(request);
List<ProtectiveEquipmentPerson> persons = result.persons();
// Create a GearItem object.
GearItem gear;
for (ProtectiveEquipmentPerson person : persons) {
List<ProtectiveEquipmentBodyPart> bodyParts = person.bodyParts();
if (bodyParts.isEmpty()) {
System.out.println("\tNo body parts detected");
} else
for (ProtectiveEquipmentBodyPart bodyPart : bodyParts) {
List<EquipmentDetection> equipmentDetections = bodyPart.equipmentDetections();
if (equipmentDetections.isEmpty()) {
System.out.println("\t\tNo PPE Detected on " + bodyPart.name());
} else {
for (EquipmentDetection item : equipmentDetections) {
gear = new GearItem();
gear.setKey(key);
String itemType = item.type().toString();
String confidence = item.confidence().toString();
String myDesc = "Item: " + item.type() + ". Confidence: " + item.confidence().toString();
String bodyPartDes = "Covers body part: " + item.coversBodyPart().value().toString() + ". Confidence: " + item.coversBodyPart().confidence().toString();
gear.setName(itemType);
gear.setConfidence(confidence);
gear.setItemDescription(myDesc);
gear.setBodyCoverDescription(bodyPartDes);
// push the object.
gearList.add(gear);
}
}
}
}
if (gearList.isEmpty())
return null;
else
return gearList;
} catch (RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.rekognition.RekognitionClient in project aws-doc-sdk-examples by awsdocs.
the class VideoDetectFaces method StartFaceDetection.
public String StartFaceDetection(String bucket, String video) {
String startJobId = "";
try {
RekognitionClient rekClient = getRecClient();
software.amazon.awssdk.services.rekognition.model.S3Object s3Obj = S3Object.builder().bucket(bucket).name(video).build();
Video vidOb = Video.builder().s3Object(s3Obj).build();
StartFaceDetectionRequest faceDetectionRequest = StartFaceDetectionRequest.builder().jobTag("Faces").notificationChannel(getChannel()).faceAttributes(FaceAttributes.ALL).video(vidOb).build();
StartFaceDetectionResponse startLabelDetectionResult = rekClient.startFaceDetection(faceDetectionRequest);
startJobId = startLabelDetectionResult.jobId();
return startJobId;
} catch (RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.rekognition.RekognitionClient in project aws-doc-sdk-examples by awsdocs.
the class VideoDetectFaces method GetFaceResults.
// Processes the Job and returns of List of labels
public List<FaceItems> GetFaceResults(String startJobId) {
List<FaceItems> items = new ArrayList<>();
try {
RekognitionClient rekClient = getRecClient();
String paginationToken = null;
GetFaceDetectionResponse faceDetectionResponse = null;
Boolean finished = false;
String status = "";
int yy = 0;
do {
if (faceDetectionResponse != null)
paginationToken = faceDetectionResponse.nextToken();
GetFaceDetectionRequest recognitionRequest = GetFaceDetectionRequest.builder().jobId(startJobId).nextToken(paginationToken).maxResults(10).build();
// Wait until the job succeeds
while (!finished) {
faceDetectionResponse = rekClient.getFaceDetection(recognitionRequest);
status = faceDetectionResponse.jobStatusAsString();
if (status.compareTo("SUCCEEDED") == 0)
finished = true;
else {
System.out.println(yy + " status is: " + status);
Thread.sleep(1000);
}
yy++;
}
finished = false;
// Push face information to the list
List<FaceDetection> faces = faceDetectionResponse.faces();
FaceItems faceItem;
for (FaceDetection face : faces) {
faceItem = new FaceItems();
String age = face.face().ageRange().toString();
String beard = face.face().beard().toString();
String eyeglasses = face.face().eyeglasses().toString();
String eyesOpen = face.face().eyesOpen().toString();
String mustache = face.face().mustache().toString();
String smile = face.face().smile().toString();
faceItem.setAgeRange(age);
faceItem.setBeard(beard);
faceItem.setEyeglasses(eyeglasses);
faceItem.setEyesOpen(eyesOpen);
faceItem.setMustache(mustache);
faceItem.setSmile(smile);
items.add(faceItem);
}
} while (faceDetectionResponse != null && faceDetectionResponse.nextToken() != null);
return items;
} catch (RekognitionException | InterruptedException e) {
System.out.println(e.getMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.rekognition.RekognitionClient in project aws-doc-sdk-examples by awsdocs.
the class DisplayFacesFrame method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage: " + " <sourceImage> <bucketName>\n\n" + "Where:\n" + " sourceImage - the name of the image in an Amazon S3 bucket (for example, people.png). \n\n" + " bucketName - the name of the Amazon S3 bucket (for example, myBucket). \n\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String sourceImage = args[0];
String bucketName = args[1];
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder().region(region).build();
RekognitionClient rekClient = RekognitionClient.builder().region(region).build();
displayAllFaces(s3, rekClient, sourceImage, bucketName);
s3.close();
rekClient.close();
}
Aggregations