Search in sources :

Example 16 with Image

use of com.amazonaws.services.rekognition.model.Image in project aws-doc-sdk-examples by awsdocs.

the class AddFacesToCollection method main.

public static void main(String[] args) throws Exception {
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    Image image = new Image().withS3Object(new S3Object().withBucket(bucket).withName(photo));
    IndexFacesRequest indexFacesRequest = new IndexFacesRequest().withImage(image).withQualityFilter(QualityFilter.AUTO).withMaxFaces(1).withCollectionId(collectionId).withExternalImageId(photo).withDetectionAttributes("DEFAULT");
    IndexFacesResult indexFacesResult = rekognitionClient.indexFaces(indexFacesRequest);
    System.out.println("Results for " + photo);
    System.out.println("Faces indexed:");
    List<FaceRecord> faceRecords = indexFacesResult.getFaceRecords();
    for (FaceRecord faceRecord : faceRecords) {
        System.out.println("  Face ID: " + faceRecord.getFace().getFaceId());
        System.out.println("  Location:" + faceRecord.getFaceDetail().getBoundingBox().toString());
    }
    List<UnindexedFace> unindexedFaces = indexFacesResult.getUnindexedFaces();
    System.out.println("Faces not indexed:");
    for (UnindexedFace unindexedFace : unindexedFaces) {
        System.out.println("  Location:" + unindexedFace.getFaceDetail().getBoundingBox().toString());
        System.out.println("  Reasons:");
        for (String reason : unindexedFace.getReasons()) {
            System.out.println("   " + reason);
        }
    }
}
Also used : IndexFacesResult(com.amazonaws.services.rekognition.model.IndexFacesResult) IndexFacesRequest(com.amazonaws.services.rekognition.model.IndexFacesRequest) FaceRecord(com.amazonaws.services.rekognition.model.FaceRecord) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) Image(com.amazonaws.services.rekognition.model.Image) UnindexedFace(com.amazonaws.services.rekognition.model.UnindexedFace)

Example 17 with Image

use of com.amazonaws.services.rekognition.model.Image in project amplify-android by aws-amplify.

the class AWSRekognitionService method detectPlainText.

private IdentifyTextResult detectPlainText(ByteBuffer imageData) throws PredictionsException {
    DetectTextRequest request = new DetectTextRequest().withImage(new Image().withBytes(imageData));
    // Read text in the given image via Amazon Rekognition
    final DetectTextResult result;
    try {
        result = rekognition.detectText(request);
    } catch (AmazonClientException serviceException) {
        throw new PredictionsException("Amazon Rekognition encountered an error while detecting text.", serviceException, "See attached service exception for more details.");
    }
    StringBuilder fullTextBuilder = new StringBuilder();
    List<String> rawLineText = new ArrayList<>();
    List<IdentifiedText> words = new ArrayList<>();
    List<IdentifiedText> lines = new ArrayList<>();
    for (TextDetection detection : result.getTextDetections()) {
        TextTypes type = TextTypes.fromValue(detection.getType());
        switch(type) {
            case LINE:
                rawLineText.add(detection.getDetectedText());
                lines.add(RekognitionResultTransformers.fromTextDetection(detection));
                continue;
            case WORD:
                fullTextBuilder.append(detection.getDetectedText()).append(" ");
                words.add(RekognitionResultTransformers.fromTextDetection(detection));
                continue;
            default:
        }
    }
    return IdentifyTextResult.builder().fullText(fullTextBuilder.toString().trim()).rawLineText(rawLineText).lines(lines).words(words).build();
}
Also used : IdentifiedText(com.amplifyframework.predictions.models.IdentifiedText) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) Image(com.amazonaws.services.rekognition.model.Image) DetectTextResult(com.amazonaws.services.rekognition.model.DetectTextResult) TextTypes(com.amazonaws.services.rekognition.model.TextTypes) TextDetection(com.amazonaws.services.rekognition.model.TextDetection) DetectTextRequest(com.amazonaws.services.rekognition.model.DetectTextRequest) PredictionsException(com.amplifyframework.predictions.PredictionsException)

Example 18 with Image

use of com.amazonaws.services.rekognition.model.Image in project amplify-android by aws-amplify.

the class AWSRekognitionService method detectLabels.

private List<Label> detectLabels(ByteBuffer imageData) throws PredictionsException {
    DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image().withBytes(imageData));
    // Detect labels in the given image via Amazon Rekognition
    final DetectLabelsResult result;
    try {
        result = rekognition.detectLabels(request);
    } catch (AmazonClientException serviceException) {
        throw new PredictionsException("Amazon Rekognition encountered an error while detecting labels.", serviceException, "See attached service exception for more details.");
    }
    List<Label> labels = new ArrayList<>();
    for (com.amazonaws.services.rekognition.model.Label rekognitionLabel : result.getLabels()) {
        List<String> parents = new ArrayList<>();
        for (Parent parent : rekognitionLabel.getParents()) {
            parents.add(parent.getName());
        }
        List<RectF> boxes = new ArrayList<>();
        for (Instance instance : rekognitionLabel.getInstances()) {
            boxes.add(RekognitionResultTransformers.fromBoundingBox(instance.getBoundingBox()));
        }
        Label amplifyLabel = Label.builder().value(rekognitionLabel.getName()).confidence(rekognitionLabel.getConfidence()).parentLabels(parents).boxes(boxes).build();
        labels.add(amplifyLabel);
    }
    return labels;
}
Also used : Parent(com.amazonaws.services.rekognition.model.Parent) Instance(com.amazonaws.services.rekognition.model.Instance) AmazonClientException(com.amazonaws.AmazonClientException) Label(com.amplifyframework.predictions.models.Label) ModerationLabel(com.amazonaws.services.rekognition.model.ModerationLabel) ArrayList(java.util.ArrayList) Image(com.amazonaws.services.rekognition.model.Image) DetectLabelsResult(com.amazonaws.services.rekognition.model.DetectLabelsResult) RectF(android.graphics.RectF) DetectLabelsRequest(com.amazonaws.services.rekognition.model.DetectLabelsRequest) PredictionsException(com.amplifyframework.predictions.PredictionsException)

Aggregations

Image (com.amazonaws.services.rekognition.model.Image)18 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)11 S3Object (com.amazonaws.services.rekognition.model.S3Object)7 AmazonClientException (com.amazonaws.AmazonClientException)6 PredictionsException (com.amplifyframework.predictions.PredictionsException)6 ArrayList (java.util.ArrayList)6 AmazonRekognitionException (com.amazonaws.services.rekognition.model.AmazonRekognitionException)5 RectF (android.graphics.RectF)4 DetectFacesRequest (com.amazonaws.services.rekognition.model.DetectFacesRequest)4 DetectFacesResult (com.amazonaws.services.rekognition.model.DetectFacesResult)4 DetectLabelsRequest (com.amazonaws.services.rekognition.model.DetectLabelsRequest)4 DetectLabelsResult (com.amazonaws.services.rekognition.model.DetectLabelsResult)4 FaceDetail (com.amazonaws.services.rekognition.model.FaceDetail)4 BoundingBox (com.amazonaws.services.rekognition.model.BoundingBox)3 ComparedFace (com.amazonaws.services.rekognition.model.ComparedFace)3 Label (com.amazonaws.services.rekognition.model.Label)3 ModerationLabel (com.amazonaws.services.rekognition.model.ModerationLabel)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3