associateFaces method

Future<AssociateFacesResponse> associateFaces({
  1. required String collectionId,
  2. required List<String> faceIds,
  3. required String userId,
  4. String? clientRequestToken,
  5. double? userMatchThreshold,
})

Associates one or more faces with an existing UserID. Takes an array of FaceIds. Each FaceId that are present in the FaceIds list is associated with the provided UserID. The number of FaceIds that can be used as input in a single request is limited to 100.

Note that the total number of faces that can be associated with a single UserID is also limited to 100. Once a UserID has 100 faces associated with it, no additional faces can be added. If more API calls are made after the limit is reached, a ServiceQuotaExceededException will result.

The UserMatchThreshold parameter specifies the minimum user match confidence required for the face to be associated with a UserID that has at least one FaceID already associated. This ensures that the FaceIds are associated with the right UserID. The value ranges from 0-100 and default value is 75.

If successful, an array of AssociatedFace objects containing the associated FaceIds is returned. If a given face is already associated with the given UserID, it will be ignored and will not be returned in the response. If a given face is already associated to a different UserID, isn't found in the collection, doesn’t meet the UserMatchThreshold, or there are already 100 faces associated with the UserID, it will be returned as part of an array of UnsuccessfulFaceAssociations.

The UserStatus reflects the status of an operation which updates a UserID representation with a list of given faces. The UserStatus can be:

  • ACTIVE - All associations or disassociations of FaceID(s) for a UserID are complete.
  • CREATED - A UserID has been created, but has no FaceID(s) associated with it.
  • UPDATING - A UserID is being updated and there are current associations or disassociations of FaceID(s) taking place.

May throw AccessDeniedException. May throw ConflictException. May throw IdempotentParameterMismatchException. May throw InternalServerError. May throw InvalidParameterException. May throw ProvisionedThroughputExceededException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException.

Parameter collectionId : The ID of an existing collection containing the UserID.

Parameter faceIds : An array of FaceIDs to associate with the UserID.

Parameter userId : The ID for the existing UserID.

Parameter clientRequestToken : Idempotent token used to identify the request to AssociateFaces. If you use the same token with multiple AssociateFaces requests, the same response is returned. Use ClientRequestToken to prevent the same request from being processed more than once.

Parameter userMatchThreshold : An optional value specifying the minimum confidence in the UserID match to return. The default value is 75.

Implementation

Future<AssociateFacesResponse> associateFaces({
  required String collectionId,
  required List<String> faceIds,
  required String userId,
  String? clientRequestToken,
  double? userMatchThreshold,
}) async {
  _s.validateNumRange(
    'userMatchThreshold',
    userMatchThreshold,
    0,
    100,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'RekognitionService.AssociateFaces'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'CollectionId': collectionId,
      'FaceIds': faceIds,
      'UserId': userId,
      'ClientRequestToken':
          clientRequestToken ?? _s.generateIdempotencyToken(),
      if (userMatchThreshold != null)
        'UserMatchThreshold': userMatchThreshold,
    },
  );

  return AssociateFacesResponse.fromJson(jsonResponse.body);
}