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);
}
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);
}
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;
}
Aggregations