use of software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentPerson in project aws-doc-sdk-examples by awsdocs.
the class DetectPPE method displayGear.
// snippet-start:[rekognition.java2.detect_ppe.main]
public static void displayGear(S3Client s3, RekognitionClient rekClient, String sourceImage, String bucketName) {
byte[] data = getObjectBytes(s3, bucketName, sourceImage);
InputStream is = new ByteArrayInputStream(data);
try {
ProtectiveEquipmentSummarizationAttributes summarizationAttributes = ProtectiveEquipmentSummarizationAttributes.builder().minConfidence(80F).requiredEquipmentTypesWithStrings("FACE_COVER", "HAND_COVER", "HEAD_COVER").build();
SdkBytes sourceBytes = SdkBytes.fromInputStream(is);
software.amazon.awssdk.services.rekognition.model.Image souImage = Image.builder().bytes(sourceBytes).build();
DetectProtectiveEquipmentRequest request = DetectProtectiveEquipmentRequest.builder().image(souImage).summarizationAttributes(summarizationAttributes).build();
DetectProtectiveEquipmentResponse result = rekClient.detectProtectiveEquipment(request);
List<ProtectiveEquipmentPerson> persons = result.persons();
for (ProtectiveEquipmentPerson person : persons) {
System.out.println("ID: " + person.id());
List<ProtectiveEquipmentBodyPart> bodyParts = person.bodyParts();
if (bodyParts.isEmpty()) {
System.out.println("\tNo body parts detected");
} else
for (ProtectiveEquipmentBodyPart bodyPart : bodyParts) {
System.out.println("\t" + bodyPart.name() + ". Confidence: " + bodyPart.confidence().toString());
List<EquipmentDetection> equipmentDetections = bodyPart.equipmentDetections();
if (equipmentDetections.isEmpty()) {
System.out.println("\t\tNo PPE Detected on " + bodyPart.name());
} else {
for (EquipmentDetection item : equipmentDetections) {
System.out.println("\t\tItem: " + item.type() + ". Confidence: " + item.confidence().toString());
System.out.println("\t\tCovers body part: " + item.coversBodyPart().value().toString() + ". Confidence: " + item.coversBodyPart().confidence().toString());
System.out.println("\t\tBounding Box");
BoundingBox box = item.boundingBox();
System.out.println("\t\tLeft: " + box.left().toString());
System.out.println("\t\tTop: " + box.top().toString());
System.out.println("\t\tWidth: " + box.width().toString());
System.out.println("\t\tHeight: " + box.height().toString());
System.out.println("\t\tConfidence: " + item.confidence().toString());
System.out.println();
}
}
}
}
System.out.println("Person ID Summary\n-----------------");
DisplaySummary("With required equipment", result.summary().personsWithRequiredEquipment());
DisplaySummary("Without required equipment", result.summary().personsWithoutRequiredEquipment());
DisplaySummary("Indeterminate", result.summary().personsIndeterminate());
} catch (RekognitionException e) {
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
}
}
use of software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentPerson 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;
}
Aggregations