Search in sources :

Example 1 with FaceMatch

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

the class SearchFaceMatchingImageCollection method searchFaceInCollection.

// snippet-start:[rekognition.java2.search_faces_collection.main]
public static void searchFaceInCollection(RekognitionClient rekClient, String collectionId, String sourceImage) {
    try {
        InputStream sourceStream = new FileInputStream(new File(sourceImage));
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        Image souImage = Image.builder().bytes(sourceBytes).build();
        SearchFacesByImageRequest facesByImageRequest = SearchFacesByImageRequest.builder().image(souImage).maxFaces(10).faceMatchThreshold(70F).collectionId(collectionId).build();
        SearchFacesByImageResponse imageResponse = rekClient.searchFacesByImage(facesByImageRequest);
        // 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 | FileNotFoundException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : SdkBytes(software.amazon.awssdk.core.SdkBytes) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SearchFacesByImageRequest(software.amazon.awssdk.services.rekognition.model.SearchFacesByImageRequest) FileNotFoundException(java.io.FileNotFoundException) SearchFacesByImageResponse(software.amazon.awssdk.services.rekognition.model.SearchFacesByImageResponse) Image(software.amazon.awssdk.services.rekognition.model.Image) File(java.io.File) FaceMatch(software.amazon.awssdk.services.rekognition.model.FaceMatch) FileInputStream(java.io.FileInputStream)

Example 2 with FaceMatch

use of software.amazon.awssdk.services.rekognition.model.FaceMatch 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)

Aggregations

FaceMatch (software.amazon.awssdk.services.rekognition.model.FaceMatch)2 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 Image (software.amazon.awssdk.services.rekognition.model.Image)1 SearchFacesByImageRequest (software.amazon.awssdk.services.rekognition.model.SearchFacesByImageRequest)1 SearchFacesByImageResponse (software.amazon.awssdk.services.rekognition.model.SearchFacesByImageResponse)1 SearchFacesRequest (software.amazon.awssdk.services.rekognition.model.SearchFacesRequest)1 SearchFacesResponse (software.amazon.awssdk.services.rekognition.model.SearchFacesResponse)1