You can use the SearchUsers
operation to to search for users in a specified collection that match a supplied face ID
or user ID. The operation lists the returned UserIds
ranked by the highest
similarity score above the requested UserMatchThreshold. The user ID is created in the
CreateUsers operation. For more information, see Managing users in a collection.
To search users (SDK)
-
If you haven't already:
-
Create or update a user with
AmazonRekognitionFullAccess
permissions. For more information, see Step 1: Set up an AWS account and create a User. -
Install and configure the AWS CLI and the AWS SDKs. For more information, see Step 2: Set up the AWS CLI and AWS SDKs.
-
-
Use the following examples to call the
SearchUsers
operation.This Java example searchers the users in a collection using the
SearchUsers
operation.import com.amazonaws.services.rekognition.AmazonRekognition; import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; import com.amazonaws.services.rekognition.model.UserMatch; import com.amazonaws.services.rekognition.model.SearchUsersRequest; import com.amazonaws.services.rekognition.model.SearchUsersResult; import com.amazonaws.services.rekognition.model.UserMatch; public class SearchUsers { //Replace collectionId and faceId with the values you want to use. public static final String collectionId = "MyCollection"; public static final String faceId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; public static final String userd = 'demo-user'; public static void main(String[] args) throws Exception { AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); // Search collection for faces matching the user id. SearchUsersRequest request = new SearchUsersRequest() .withCollectionId(collectionId) .withUserId(userId); SearchUsersResult result = rekognitionClient.searchUsers(request); System.out.println("Printing first search result with matched user and similarity score"); for (UserMatch match: result.getUserMatches()) { System.out.println(match.getUser().getUserId() + " with similarity score " + match.getSimilarity()); } // Search collection for faces matching the face id. SearchUsersRequest request1 = new SearchUsersRequest() .withCollectionId(collectionId) .withFaceId(faceId); SearchUsersResult result1 = rekognitionClient.searchUsers(request1); System.out.println("Printing second search result with matched user and similarity score"); for (UserMatch match: result1.getUserMatches()) { System.out.println(match.getUser().getUserId() + " with similarity score " + match.getSimilarity()); } }
SearchUsers operation request
Given a FaceID or UserID, SearchUsers searches the specified CollectionID for user matches. By default, SearchUsers returns UserIDs for which the similarity score is greater than 80%. The similarity indicates how closely the UserID matches the provided FaceID or UserID. If multiple UserIDs are returned, they are listed in order of highest similarity score to lowest. Optionally, you can use the UserMatchThreshold to specify a different value. For more information, see Managing users in a collection.
The following is an example of a SearchUsers request using
UserId
:
{
"CollectionId": "MyCollection",
"UserId": "demoUser1",
"MaxUsers": 2,
"UserMatchThreshold": 99
}
The following is an example of a SearchUsers request using
FaceId
:
{
"CollectionId": "MyCollection",
"FaceId": "bff43c40-cfa7-4b94-bed8-8a08b2205107",
"MaxUsers": 2,
"UserMatchThreshold": 99
}
SearchUsers operation response
If searching with a FaceId
, the response for SearchUsers includes the
FaceId
for the SearchedFace
, as well as a list of
UserMatches
and the UserId
and UserStatus
for each User.
{
"SearchedFace": {
"FaceId": "bff43c40-cfa7-4b94-bed8-8a08b2205107"
},
"UserMatches": [
{
"User": {
"UserId": "demoUser1",
"UserStatus": "ACTIVE"
},
"Similarity": 100.0
},
{
"User": {
"UserId": "demoUser2",
"UserStatus": "ACTIVE"
},
"Similarity": 99.97946166992188
}
],
"FaceModelVersion": "6"
}
If searching with a UserId
, the response for SearchUsers includes the
UserId
for the SearchedUser
, in addition to the other
response elements.
{
"SearchedUser": {
"UserId": "demoUser1"
},
"UserMatches": [
{
"User": {
"UserId": "demoUser2",
"UserStatus": "ACTIVE"
},
"Similarity": 99.97946166992188
}
],
"FaceModelVersion": "6"
}