searchFaces method
For a given input face ID, searches for matching faces in the collection
the face belongs to. You get a face ID when you add a face to the
collection using the IndexFaces operation. The operation compares
the features of the input face with faces in the specified collection.
The operation response returns an array of faces that match, ordered by
similarity score with the highest similarity first. More specifically, it
is an array of metadata for each face match that is found. Along with the
metadata, the response also includes a confidence
value for
each face match, indicating the confidence that the specific face matches
the input face.
For an example, see Searching for a Face Using Its Face ID in the Amazon Rekognition Developer Guide.
This operation requires permissions to perform the
rekognition:SearchFaces
action.
May throw InvalidParameterException. May throw AccessDeniedException. May throw InternalServerError. May throw ThrottlingException. May throw ProvisionedThroughputExceededException. May throw ResourceNotFoundException.
Parameter collectionId
:
ID of the collection the face belongs to.
Parameter faceId
:
ID of a face to find matches for in the collection.
Parameter faceMatchThreshold
:
Optional value specifying the minimum confidence in the face match to
return. For example, don't return any matches where confidence in matches
is less than 70%. The default value is 80%.
Parameter maxFaces
:
Maximum number of faces to return. The operation returns the maximum
number of faces with the highest confidence in the match.
Implementation
Future<SearchFacesResponse> searchFaces({
required String collectionId,
required String faceId,
double? faceMatchThreshold,
int? maxFaces,
}) async {
ArgumentError.checkNotNull(collectionId, 'collectionId');
_s.validateStringLength(
'collectionId',
collectionId,
1,
255,
isRequired: true,
);
ArgumentError.checkNotNull(faceId, 'faceId');
_s.validateNumRange(
'faceMatchThreshold',
faceMatchThreshold,
0,
100,
);
_s.validateNumRange(
'maxFaces',
maxFaces,
1,
4096,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'RekognitionService.SearchFaces'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'CollectionId': collectionId,
'FaceId': faceId,
if (faceMatchThreshold != null)
'FaceMatchThreshold': faceMatchThreshold,
if (maxFaces != null) 'MaxFaces': maxFaces,
},
);
return SearchFacesResponse.fromJson(jsonResponse.body);
}