翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
ユーザーへの顔の関連付け
AssociateFaces オペレーションを使用して、複数の個々の顔を 1 人のユーザーに関連付けることができます。顔をユーザーに関連付けるには、まずコレクションとユーザーを作成する必要があります。顔ベクトルは、ユーザーベクトルが存在するコレクションと同じコレクション内に存在している必要があります。
顔を関連付けるには (SDK)
-
まだ実行していない場合:
-
AmazonRekognitionFullAccess
アクセス権限を持つユーザーを作成または更新します。詳細については、「ステップ 1: AWSアカウントを設定し、ユーザーを作成する」を参照してください。
-
と をインストール AWS CLI して設定します AWS SDKs。詳細については、「ステップ 2: AWS CLI と をセットアップする AWS SDKs」を参照してください。
-
以下の例を使用して、AssociateFaces
オペレーションを呼び出します。
- Java
-
この Java コード例では、顔をユーザーに関連付けます。
import java.util.Arrays;
import java.util.List;
import com.amazonaws.services.rekognition.AmazonRekognition;
import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
import com.amazonaws.services.rekognition.model.AssociateFacesRequest;
import com.amazonaws.services.rekognition.model.AssociateFacesResult;
public class AssociateFaces {
public static void main(String[] args) throws Exception {
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
/* Replace the below configurations to allow you successfully run the example
@collectionId: The collection where user and faces are stored
@userId: The user which faces will get associated to
@faceIds: The list of face IDs that will get associated to the given user
@userMatchThreshold: Minimum User match confidence required for the face to
be associated with a User that has at least one faceID already associated
*/
String collectionId = "MyCollection";
String userId = "demoUser";
String faceId1 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
String faceId2 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
List<String> faceIds = Arrays.asList(faceid1,faceid2);
float userMatchThreshold = 0f;
System.out.println("Associating faces to the existing user: " +
userId);
AssociateFacesRequest request = new AssociateFacesRequest()
.withCollectionId(collectionId)
.withUserId(userId)
.withFaceIds(faceIds)
.withUserMatchThreshold(userMatchThreshold);
AssociateFacesResult result = rekognitionClient.associateFaces(request);
System.out.println("Successful face associations: " + result.getAssociatedFaces().size());
System.out.println("Unsuccessful face associations: " + result.getUnsuccessfulFaceAssociations().size());
}
}
- AWS CLI
-
この AWS CLI コマンドは、 associate-faces
CLIオペレーションを使用して顔をユーザーと関連付けます。
aws rekognition associate-faces --user-id user-id
--face-ids face-id-1
face-id-2
--collection-id collection-name
--region region-name
- Python
-
この Python コード例では、顔をユーザーに関連付けます。
from botocore.exceptions import ClientError
import boto3
import logging
logger = logging.getLogger(__name__)
session = boto3.Session(profile_name='profile-name')
client = session.client('rekognition')
def associate_faces(collection_id, user_id, face_ids):
"""
Associate stored faces within collection to the given user
:param collection_id: The ID of the collection where user and faces are stored.
:param user_id: The ID of the user that we want to associate faces to
:param face_ids: The list of face IDs to be associated to the given user
:return: response of AssociateFaces API
"""
logger.info(f'Associating faces to user: {user_id}, {face_ids}')
try:
response = client.associate_faces(
CollectionId=collection_id,
UserId=user_id,
FaceIds=face_ids
)
print(f'- associated {len(response["AssociatedFaces"])} faces')
except ClientError:
logger.exception("Failed to associate faces to the given user")
raise
else:
print(response)
return response
def main():
face_ids = ["faceId1", "faceId2"]
collection_id = "collection-id"
user_id = "user-id"
associate_faces(collection_id, user_id, face_ids)
if __name__ == "__main__":
main()
AssociateFaces オペレーションレスポンス
AssociateFaces
のレスポンスには、関連付け解除のリクエストのステータスである UserStatus
と、関連付ける FaceIds
のリストが含まれています。UnsuccessfulFaceAssociations
のリストも返されます。AssociateFaces
にリクエストを送信した後、オペレーションが完了するまでに 1 分ほどかかる場合があります。
このため、 UserStatus が返され、次の値を持つことができます。
-
CREATED - 「ユーザー」が正常に作成され、現在顔が関連付けられていないことを示します。「ユーザー」は、AssociateFaces「」呼び出しが成功する前に、この状態になります。
-
UPDATING - 「ユーザー」が更新され、新しく関連付け/関連付け解除された顔が反映され、数秒ACTIVEで になることを示します。検索結果にこのステータスの「ユーザー」が含まれる場合、お客様は、返される結果からそのユーザーを無視することを選択できます。
-
ACTIVE - 「ユーザー」が更新され、関連付け/関連付け解除されたすべての顔が反映され、検索可能な状態であることを示します。
{
"UnsuccessfulFaceAssociations": [
{
"Reasons": [
"LOW_MATCH_CONFIDENCE"
],
"FaceId": "f5817d37-94f6-0000-bfee-1a2b3c4d5e6f",
"Confidence": 0.9375374913215637
},
{
"Reasons": [
"ASSOCIATED_TO_A_DIFFERENT_IDENTITY"
],
"FaceId": "851cb847-dccc-1111-bfee-1a2b3c4d5e6f",
"UserId": "demoUser2"
}
],
"UserStatus": "UPDATING",
"AssociatedFaces": [
{
"FaceId": "35ebbb41-7f67-2222-bfee-1a2b3c4d5e6f"
}
]
}