Search in sources :

Example 16 with RekognitionException

use of software.amazon.awssdk.services.rekognition.model.RekognitionException in project aws-doc-sdk-examples by awsdocs.

the class SearchFaceMatchingIdCollection method searchFacebyId.

// snippet-start:[rekognition.java2.match_faces_collection.main]
public static void searchFacebyId(RekognitionClient rekClient, String collectionId, String faceId) {
    try {
        SearchFacesRequest searchFacesRequest = SearchFacesRequest.builder().collectionId(collectionId).faceId(faceId).faceMatchThreshold(70F).maxFaces(2).build();
        SearchFacesResponse imageResponse = rekClient.searchFaces(searchFacesRequest);
        // Display the results.
        System.out.println("Faces matching in the collection");
        List<FaceMatch> faceImageMatches = imageResponse.faceMatches();
        for (FaceMatch face : faceImageMatches) {
            System.out.println("The similarity level is  " + face.similarity());
            System.out.println();
        }
    } catch (RekognitionException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : SearchFacesResponse(software.amazon.awssdk.services.rekognition.model.SearchFacesResponse) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) SearchFacesRequest(software.amazon.awssdk.services.rekognition.model.SearchFacesRequest) FaceMatch(software.amazon.awssdk.services.rekognition.model.FaceMatch)

Example 17 with RekognitionException

use of software.amazon.awssdk.services.rekognition.model.RekognitionException in project aws-doc-sdk-examples by awsdocs.

the class VideoDetectSegment method StartSegmentDetection.

// snippet-start:[rekognition.java2.recognize_video_segments.main]
public static void StartSegmentDetection(RekognitionClient rekClient, NotificationChannel channel, String bucket, String video) {
    try {
        S3Object s3Obj = S3Object.builder().bucket(bucket).name(video).build();
        Video vidOb = Video.builder().s3Object(s3Obj).build();
        StartShotDetectionFilter cueDetectionFilter = StartShotDetectionFilter.builder().minSegmentConfidence(60F).build();
        StartTechnicalCueDetectionFilter technicalCueDetectionFilter = StartTechnicalCueDetectionFilter.builder().minSegmentConfidence(60F).build();
        StartSegmentDetectionFilters filters = StartSegmentDetectionFilters.builder().shotFilter(cueDetectionFilter).technicalCueFilter(technicalCueDetectionFilter).build();
        StartSegmentDetectionRequest segDetectionRequest = StartSegmentDetectionRequest.builder().jobTag("DetectingLabels").notificationChannel(channel).segmentTypes(SegmentType.TECHNICAL_CUE, SegmentType.SHOT).video(vidOb).filters(filters).build();
        StartSegmentDetectionResponse segDetectionResponse = rekClient.startSegmentDetection(segDetectionRequest);
        startJobId = segDetectionResponse.jobId();
    } catch (RekognitionException e) {
        e.getMessage();
        System.exit(1);
    }
}
Also used : StartTechnicalCueDetectionFilter(software.amazon.awssdk.services.rekognition.model.StartTechnicalCueDetectionFilter) StartSegmentDetectionFilters(software.amazon.awssdk.services.rekognition.model.StartSegmentDetectionFilters) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) Video(software.amazon.awssdk.services.rekognition.model.Video) StartSegmentDetectionResponse(software.amazon.awssdk.services.rekognition.model.StartSegmentDetectionResponse) S3Object(software.amazon.awssdk.services.rekognition.model.S3Object) StartShotDetectionFilter(software.amazon.awssdk.services.rekognition.model.StartShotDetectionFilter) StartSegmentDetectionRequest(software.amazon.awssdk.services.rekognition.model.StartSegmentDetectionRequest)

Example 18 with RekognitionException

use of software.amazon.awssdk.services.rekognition.model.RekognitionException in project aws-doc-sdk-examples by awsdocs.

the class AddFacesToCollection method addToCollection.

// snippet-start:[rekognition.java2.add_faces_collection.main]
public static void addToCollection(RekognitionClient rekClient, String collectionId, String sourceImage) {
    try {
        InputStream sourceStream = new FileInputStream(sourceImage);
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        Image souImage = Image.builder().bytes(sourceBytes).build();
        IndexFacesRequest facesRequest = IndexFacesRequest.builder().collectionId(collectionId).image(souImage).maxFaces(1).qualityFilter(QualityFilter.AUTO).detectionAttributes(Attribute.DEFAULT).build();
        IndexFacesResponse facesResponse = rekClient.indexFaces(facesRequest);
        // Display the results.
        System.out.println("Results for the image");
        System.out.println("\n Faces indexed:");
        List<FaceRecord> faceRecords = facesResponse.faceRecords();
        for (FaceRecord faceRecord : faceRecords) {
            System.out.println("  Face ID: " + faceRecord.face().faceId());
            System.out.println("  Location:" + faceRecord.faceDetail().boundingBox().toString());
        }
        List<UnindexedFace> unindexedFaces = facesResponse.unindexedFaces();
        System.out.println("Faces not indexed:");
        for (UnindexedFace unindexedFace : unindexedFaces) {
            System.out.println("  Location:" + unindexedFace.faceDetail().boundingBox().toString());
            System.out.println("  Reasons:");
            for (Reason reason : unindexedFace.reasons()) {
                System.out.println("Reason:  " + reason);
            }
        }
    } catch (RekognitionException | FileNotFoundException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : IndexFacesRequest(software.amazon.awssdk.services.rekognition.model.IndexFacesRequest) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Image(software.amazon.awssdk.services.rekognition.model.Image) FileInputStream(java.io.FileInputStream) Reason(software.amazon.awssdk.services.rekognition.model.Reason) SdkBytes(software.amazon.awssdk.core.SdkBytes) IndexFacesResponse(software.amazon.awssdk.services.rekognition.model.IndexFacesResponse) FaceRecord(software.amazon.awssdk.services.rekognition.model.FaceRecord) UnindexedFace(software.amazon.awssdk.services.rekognition.model.UnindexedFace)

Example 19 with RekognitionException

use of software.amazon.awssdk.services.rekognition.model.RekognitionException in project aws-doc-sdk-examples by awsdocs.

the class CompareFaces method compareTwoFaces.

// snippet-start:[rekognition.java2.compare_faces.main]
public static void compareTwoFaces(RekognitionClient rekClient, Float similarityThreshold, String sourceImage, String targetImage) {
    try {
        InputStream sourceStream = new FileInputStream(sourceImage);
        InputStream tarStream = new FileInputStream(targetImage);
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        SdkBytes targetBytes = SdkBytes.fromInputStream(tarStream);
        // Create an Image object for the source image.
        Image souImage = Image.builder().bytes(sourceBytes).build();
        Image tarImage = Image.builder().bytes(targetBytes).build();
        CompareFacesRequest facesRequest = CompareFacesRequest.builder().sourceImage(souImage).targetImage(tarImage).similarityThreshold(similarityThreshold).build();
        // Compare the two images.
        CompareFacesResponse compareFacesResult = rekClient.compareFaces(facesRequest);
        List<CompareFacesMatch> faceDetails = compareFacesResult.faceMatches();
        for (CompareFacesMatch match : faceDetails) {
            ComparedFace face = match.face();
            BoundingBox position = face.boundingBox();
            System.out.println("Face at " + position.left().toString() + " " + position.top() + " matches with " + face.confidence().toString() + "% confidence.");
        }
        List<ComparedFace> uncompared = compareFacesResult.unmatchedFaces();
        System.out.println("There was " + uncompared.size() + " face(s) that did not match");
        System.out.println("Source image rotation: " + compareFacesResult.sourceImageOrientationCorrection());
        System.out.println("target image rotation: " + compareFacesResult.targetImageOrientationCorrection());
    } catch (RekognitionException | FileNotFoundException e) {
        System.out.println("Failed to load source image " + sourceImage);
        System.exit(1);
    }
}
Also used : RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Image(software.amazon.awssdk.services.rekognition.model.Image) CompareFacesMatch(software.amazon.awssdk.services.rekognition.model.CompareFacesMatch) ComparedFace(software.amazon.awssdk.services.rekognition.model.ComparedFace) FileInputStream(java.io.FileInputStream) CompareFacesResponse(software.amazon.awssdk.services.rekognition.model.CompareFacesResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) BoundingBox(software.amazon.awssdk.services.rekognition.model.BoundingBox) CompareFacesRequest(software.amazon.awssdk.services.rekognition.model.CompareFacesRequest)

Example 20 with RekognitionException

use of software.amazon.awssdk.services.rekognition.model.RekognitionException in project aws-doc-sdk-examples by awsdocs.

the class DeleteFacesFromCollection method deleteFacesCollection.

// snippet-start:[rekognition.java2.delete_faces_collection.main]
public static void deleteFacesCollection(RekognitionClient rekClient, String collectionId, String faceId) {
    try {
        DeleteFacesRequest deleteFacesRequest = DeleteFacesRequest.builder().collectionId(collectionId).faceIds(faceId).build();
        rekClient.deleteFaces(deleteFacesRequest);
        System.out.println("The face was deleted from the collection.");
    } catch (RekognitionException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : DeleteFacesRequest(software.amazon.awssdk.services.rekognition.model.DeleteFacesRequest) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException)

Aggregations

RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)33 Image (software.amazon.awssdk.services.rekognition.model.Image)12 SdkBytes (software.amazon.awssdk.core.SdkBytes)10 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 InputStream (java.io.InputStream)8 S3Object (software.amazon.awssdk.services.rekognition.model.S3Object)8 Video (software.amazon.awssdk.services.rekognition.model.Video)6 VideoMetadata (software.amazon.awssdk.services.rekognition.model.VideoMetadata)6 File (java.io.File)2 Celebrity (software.amazon.awssdk.services.rekognition.model.Celebrity)2 ComparedFace (software.amazon.awssdk.services.rekognition.model.ComparedFace)2 DetectLabelsRequest (software.amazon.awssdk.services.rekognition.model.DetectLabelsRequest)2 DetectLabelsResponse (software.amazon.awssdk.services.rekognition.model.DetectLabelsResponse)2 FaceMatch (software.amazon.awssdk.services.rekognition.model.FaceMatch)2 Label (software.amazon.awssdk.services.rekognition.model.Label)2 RecognizeCelebritiesRequest (software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesRequest)2 RecognizeCelebritiesResponse (software.amazon.awssdk.services.rekognition.model.RecognizeCelebritiesResponse)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1