Search in sources :

Example 16 with RekognitionClient

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();
}
Also used : Region(software.amazon.awssdk.regions.Region) RekognitionClient(software.amazon.awssdk.services.rekognition.RekognitionClient)

Example 17 with RekognitionClient

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;
}
Also used : ProtectiveEquipmentSummarizationAttributes(software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentSummarizationAttributes) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) ArrayList(java.util.ArrayList) ProtectiveEquipmentBodyPart(software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentBodyPart) Image(software.amazon.awssdk.services.rekognition.model.Image) DetectProtectiveEquipmentRequest(software.amazon.awssdk.services.rekognition.model.DetectProtectiveEquipmentRequest) SdkBytes(software.amazon.awssdk.core.SdkBytes) EquipmentDetection(software.amazon.awssdk.services.rekognition.model.EquipmentDetection) ProtectiveEquipmentPerson(software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentPerson) Region(software.amazon.awssdk.regions.Region) RekognitionClient(software.amazon.awssdk.services.rekognition.RekognitionClient) ArrayList(java.util.ArrayList) List(java.util.List) DetectProtectiveEquipmentResponse(software.amazon.awssdk.services.rekognition.model.DetectProtectiveEquipmentResponse)

Example 18 with RekognitionClient

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 "";
}
Also used : S3Object(software.amazon.awssdk.services.rekognition.model.S3Object) RekognitionClient(software.amazon.awssdk.services.rekognition.RekognitionClient) software.amazon.awssdk.services.rekognition.model(software.amazon.awssdk.services.rekognition.model)

Example 19 with RekognitionClient

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;
}
Also used : ArrayList(java.util.ArrayList) RekognitionClient(software.amazon.awssdk.services.rekognition.RekognitionClient)

Example 20 with RekognitionClient

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();
}
Also used : Region(software.amazon.awssdk.regions.Region) RekognitionClient(software.amazon.awssdk.services.rekognition.RekognitionClient) S3Client(software.amazon.awssdk.services.s3.S3Client)

Aggregations

RekognitionClient (software.amazon.awssdk.services.rekognition.RekognitionClient)34 Region (software.amazon.awssdk.regions.Region)32 NotificationChannel (software.amazon.awssdk.services.rekognition.model.NotificationChannel)6 S3Client (software.amazon.awssdk.services.s3.S3Client)3 ArrayList (java.util.ArrayList)2 SqsClient (software.amazon.awssdk.services.sqs.SqsClient)2 List (java.util.List)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 software.amazon.awssdk.services.rekognition.model (software.amazon.awssdk.services.rekognition.model)1 DetectProtectiveEquipmentRequest (software.amazon.awssdk.services.rekognition.model.DetectProtectiveEquipmentRequest)1 DetectProtectiveEquipmentResponse (software.amazon.awssdk.services.rekognition.model.DetectProtectiveEquipmentResponse)1 EquipmentDetection (software.amazon.awssdk.services.rekognition.model.EquipmentDetection)1 Image (software.amazon.awssdk.services.rekognition.model.Image)1 ProtectiveEquipmentBodyPart (software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentBodyPart)1 ProtectiveEquipmentPerson (software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentPerson)1 ProtectiveEquipmentSummarizationAttributes (software.amazon.awssdk.services.rekognition.model.ProtectiveEquipmentSummarizationAttributes)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1 S3Object (software.amazon.awssdk.services.rekognition.model.S3Object)1