private void processTask(Message message) { String path = message.getBody(); PathSplit pathComp = new PathSplit(path); String bucket = pathComp.bucket; String key = pathComp.key; Logger.Info("Processing %s %s", bucket, key); // Rekognition: Detect Labels from S3 object DetectLabelsRequest req = new DetectLabelsRequest() .withImage(new Image().withS3Object(new S3Object().withBucket(bucket).withName(key))) .withMinConfidence(minConfidence); DetectLabelsResult result; result = rek.detectLabels(req); List<Label> labels = result.getLabels(); Logger.Debug("In %s, found: %s", key, labels); // Process downstream actions: for (LabelProcessor processor : processors) { processor.process(labels, path); } }
@Override public Parameters handleRequest(Parameters parameters, Context context) { context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]"); // Create Rekognition client using the parameters available form the runtime context AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); // Create a Rekognition request DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image() .withS3Object(new S3Object().withName(parameters.getS3key()) .withBucket(parameters.getS3Bucket()))); // Call the Rekognition Service DetectLabelsResult result = rekognitionClient.detectLabels(request); // Transfer labels and confidence scores over to Parameter POJO for (Label label : result.getLabels()) { parameters.getRekognitionLabels().put(label.getName(), label.getConfidence()); } context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]"); // Return the result (will be serialised to JSON) return parameters; }
/** * Hopefully, Label is serializable, otherwise it needs to return a list of * POJOs. * * @return */ public List<Label> getLabels(ByteBuffer imageBytes) { AmazonRekognition client = getClient(); DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageBytes)).withMaxLabels(maxLabels).withMinConfidence(minConfidence); DetectLabelsResult result = client.detectLabels(request); List<Label> labels = result.getLabels(); lastImage = imageBytes; lastLabels = labels; return labels; }
public List<FaceDetail> getFaces(ByteBuffer imageBytes, Integer width, Integer height){ DetectFacesRequest request = new DetectFacesRequest() .withImage(new Image() .withBytes((imageBytes))) .withAttributes(Attribute.ALL); DetectFacesResult result = getClient().detectFaces(request); System.out.println("Orientation: " + result.getOrientationCorrection() + "\n"); List <FaceDetail> faceDetails = result.getFaceDetails(); for (FaceDetail face: faceDetails) { System.out.println("Face:"); ShowBoundingBoxPositions(height, width, face.getBoundingBox(), result.getOrientationCorrection()); AgeRange ageRange = face.getAgeRange(); System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old."); System.out.println(); } return faceDetails; }