Search in sources :

Example 1 with Face

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

the class VideoDetect method GetResultsFaceSearchCollection.

// Gets the results of a collection face search by calling GetFaceSearch.
// The search is started by calling StartFaceSearch.
// ==================================================================
private static void GetResultsFaceSearchCollection() throws Exception {
    GetFaceSearchResult faceSearchResult = null;
    int maxResults = 10;
    String paginationToken = null;
    do {
        if (faceSearchResult != null) {
            paginationToken = faceSearchResult.getNextToken();
        }
        faceSearchResult = rek.getFaceSearch(new GetFaceSearchRequest().withJobId(startJobId).withMaxResults(maxResults).withNextToken(paginationToken).withSortBy(FaceSearchSortBy.TIMESTAMP));
        VideoMetadata videoMetaData = faceSearchResult.getVideoMetadata();
        System.out.println("Format: " + videoMetaData.getFormat());
        System.out.println("Codec: " + videoMetaData.getCodec());
        System.out.println("Duration: " + videoMetaData.getDurationMillis());
        System.out.println("FrameRate: " + videoMetaData.getFrameRate());
        System.out.println();
        // Show search results
        List<PersonMatch> matches = faceSearchResult.getPersons();
        for (PersonMatch match : matches) {
            long milliSeconds = match.getTimestamp();
            System.out.print("Timestamp: " + Long.toString(milliSeconds));
            System.out.println(" Person number: " + match.getPerson().getIndex());
            List<FaceMatch> faceMatches = match.getFaceMatches();
            if (faceMatches != null) {
                System.out.println("Matches in collection...");
                for (FaceMatch faceMatch : faceMatches) {
                    Face face = faceMatch.getFace();
                    System.out.println("Face Id: " + face.getFaceId());
                    System.out.println("Similarity: " + faceMatch.getSimilarity().toString());
                    System.out.println();
                }
            }
            System.out.println();
        }
        System.out.println();
    } while (faceSearchResult != null && faceSearchResult.getNextToken() != null);
}
Also used : PersonMatch(com.amazonaws.services.rekognition.model.PersonMatch) GetFaceSearchRequest(com.amazonaws.services.rekognition.model.GetFaceSearchRequest) GetFaceSearchResult(com.amazonaws.services.rekognition.model.GetFaceSearchResult) Face(com.amazonaws.services.rekognition.model.Face) FaceMatch(com.amazonaws.services.rekognition.model.FaceMatch) VideoMetadata(com.amazonaws.services.rekognition.model.VideoMetadata)

Example 2 with Face

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

the class ListFacesInCollection method main.

public static void main(String[] args) throws Exception {
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    ObjectMapper objectMapper = new ObjectMapper();
    ListFacesResult listFacesResult = null;
    System.out.println("Faces in collection " + collectionId);
    String paginationToken = null;
    do {
        if (listFacesResult != null) {
            paginationToken = listFacesResult.getNextToken();
        }
        ListFacesRequest listFacesRequest = new ListFacesRequest().withCollectionId(collectionId).withMaxResults(1).withNextToken(paginationToken);
        listFacesResult = rekognitionClient.listFaces(listFacesRequest);
        List<Face> faces = listFacesResult.getFaces();
        for (Face face : faces) {
            System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
        }
    } while (listFacesResult != null && listFacesResult.getNextToken() != null);
}
Also used : AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) ListFacesResult(com.amazonaws.services.rekognition.model.ListFacesResult) ListFacesRequest(com.amazonaws.services.rekognition.model.ListFacesRequest) Face(com.amazonaws.services.rekognition.model.Face) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Face

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

the class AWSRekognitionService method detectEntityMatches.

private List<EntityMatch> detectEntityMatches(ByteBuffer imageData, int maxEntities, String collectionId) throws PredictionsException {
    SearchFacesByImageRequest request = new SearchFacesByImageRequest().withImage(new Image().withBytes(imageData)).withMaxFaces(maxEntities).withCollectionId(collectionId);
    // Detect entities in the given image by matching against a collection of images
    final SearchFacesByImageResult result;
    try {
        result = rekognition.searchFacesByImage(request);
    } catch (AmazonClientException serviceException) {
        throw new PredictionsException("Amazon Rekognition encountered an error while searching for known faces.", serviceException, "See attached service exception for more details.");
    }
    List<EntityMatch> matches = new ArrayList<>();
    for (FaceMatch rekognitionMatch : result.getFaceMatches()) {
        Face face = rekognitionMatch.getFace();
        RectF box = RekognitionResultTransformers.fromBoundingBox(face.getBoundingBox());
        EntityMatch amplifyMatch = EntityMatch.builder().externalImageId(face.getExternalImageId()).confidence(rekognitionMatch.getSimilarity()).box(box).build();
        matches.add(amplifyMatch);
    }
    return matches;
}
Also used : RectF(android.graphics.RectF) SearchFacesByImageRequest(com.amazonaws.services.rekognition.model.SearchFacesByImageRequest) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) PredictionsException(com.amplifyframework.predictions.PredictionsException) EntityMatch(com.amplifyframework.predictions.models.EntityMatch) Image(com.amazonaws.services.rekognition.model.Image) SearchFacesByImageResult(com.amazonaws.services.rekognition.model.SearchFacesByImageResult) ComparedFace(com.amazonaws.services.rekognition.model.ComparedFace) Face(com.amazonaws.services.rekognition.model.Face) FaceMatch(com.amazonaws.services.rekognition.model.FaceMatch)

Aggregations

Face (com.amazonaws.services.rekognition.model.Face)3 FaceMatch (com.amazonaws.services.rekognition.model.FaceMatch)2 RectF (android.graphics.RectF)1 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 ComparedFace (com.amazonaws.services.rekognition.model.ComparedFace)1 GetFaceSearchRequest (com.amazonaws.services.rekognition.model.GetFaceSearchRequest)1 GetFaceSearchResult (com.amazonaws.services.rekognition.model.GetFaceSearchResult)1 Image (com.amazonaws.services.rekognition.model.Image)1 ListFacesRequest (com.amazonaws.services.rekognition.model.ListFacesRequest)1 ListFacesResult (com.amazonaws.services.rekognition.model.ListFacesResult)1 PersonMatch (com.amazonaws.services.rekognition.model.PersonMatch)1 SearchFacesByImageRequest (com.amazonaws.services.rekognition.model.SearchFacesByImageRequest)1 SearchFacesByImageResult (com.amazonaws.services.rekognition.model.SearchFacesByImageResult)1 VideoMetadata (com.amazonaws.services.rekognition.model.VideoMetadata)1 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 EntityMatch (com.amplifyframework.predictions.models.EntityMatch)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1