翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
ユーザー (顔 ID/ユーザー ID) を検索
SearchUsers オペレーションを使用すると、指定したコレクション内で、指定した顔 ID またはユーザー ID と一致する顔を検索できます。このオペレーションでは、リクエストされた UserMatchThreshold を超える、最も高い類似度スコアを持つ UserIds が一覧表示されます。ユーザー ID は CreateUsers オペレーションで作成されます。詳細については、「コレクション内のユーザーの管理」を参照してください。
ユーザーを検索するには (SDK)
-
まだ実行していない場合:
-
AmazonRekognitionFullAccess アクセス権限を持つユーザーを作成または更新します。詳細については、「ステップ 1: AWS アカウントを設定してユーザーを作成する」を参照してください。
-
と AWS SDKs をインストール AWS CLI して設定します。詳細については、「ステップ 2: AWS CLI と AWS SDKsを設定する」を参照してください。
-
以下の例を使用して、SearchUsers オペレーションを呼び出します。
- Java
-
この Java の例では、SearchUsers オペレーションを使用してコレクション内のユーザーを検索します。
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());
}
}
- AWS CLI
-
この AWS CLI コマンドは、 SearchUsersオペレーションを使用してコレクション内のユーザーを検索します。
aws rekognition search-users --face-id face-id --collection-id collection-id --region region-name
- Python
-
次の例では、SearchUsers オペレーションを使用してコレクション内のユーザーを検索します。
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
import boto3
from botocore.exceptions import ClientError
import logging
logger = logging.getLogger(__name__)
session = boto3.Session(profile_name='profile-name')
client = session.client('rekognition')
def search_users_by_face_id(collection_id, face_id):
"""
SearchUsers operation with face ID provided as the search source
:param collection_id: The ID of the collection where user and faces are stored.
:param face_id: The ID of the face in the collection to search for.
:return: response of SearchUsers API
"""
logger.info(f'Searching for users using a face-id: {face_id}')
try:
response = client.search_users(
CollectionId=collection_id,
FaceId=face_id
)
print(f'- found {len(response["UserMatches"])} matches')
print([f'- {x["User"]["UserId"]} - {x["Similarity"]}%' for x in response["UserMatches"]])
except ClientError:
logger.exception(f'Failed to perform SearchUsers with given face id: {face_id}')
raise
else:
print(response)
return response
def search_users_by_user_id(collection_id, user_id):
"""
SearchUsers operation with user ID provided as the search source
:param collection_id: The ID of the collection where user and faces are stored.
:param user_id: The ID of the user in the collection to search for.
:return: response of SearchUsers API
"""
logger.info(f'Searching for users using a user-id: {user_id}')
try:
response = client.search_users(
CollectionId=collection_id,
UserId=user_id
)
print(f'- found {len(response["UserMatches"])} matches')
print([f'- {x["User"]["UserId"]} - {x["Similarity"]}%' for x in response["UserMatches"]])
except ClientError:
logger.exception(f'Failed to perform SearchUsers with given face id: {user_id}')
raise
else:
print(response)
return response
def main():
collection_id = "collection-id"
user_id = "user-id"
face_id = "face_id"
search_users_by_face_id(collection_id, face_id)
search_users_by_user_id(collection_id, user_id)
if __name__ == "__main__":
main()
SearchUsers オペレーションのリクエスト
FaceID または UserID を指定すると、SearchUsers が、指定された CollectionID でユーザーが一致するものを検索します。デフォルトでは、SearchUsers は類似度スコアが 80% を超える UserID を返します。類似度は、UserID が、指定された FaceID または UserID とどの程度一致しているかを示します。複数の UserID が返された場合、類似度スコアが高いものから順に一覧表示されます。必要に応じて、UserMatchThreshold を使用して別の値を指定できます。詳細については、「コレクション内のユーザーの管理」を参照してください。
以下は、UserId を使った SearchUsers リクエストの例です。
{
"CollectionId": "MyCollection",
"UserId": "demoUser1",
"MaxUsers": 2,
"UserMatchThreshold": 99
}
以下は、FaceId を使った SearchUsers リクエストの例です。
{
"CollectionId": "MyCollection",
"FaceId": "bff43c40-cfa7-4b94-bed8-8a08b2205107",
"MaxUsers": 2,
"UserMatchThreshold": 99
}
SearchUsers オペレーションのレスポンス
FaceId を使用して検索した場合、SearchUsers のレスポンスには SearchedFace の FaceId、UserMatches のリスト、各ユーザーの UserId と UserStatus が含まれます。
{
"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"
}
UserId を使用して検索した場合、SearchUsers のレスポンスには他のレスポンス要素に加えて SearchedUser の UserId が含まれます。
{
"SearchedUser": {
"UserId": "demoUser1"
},
"UserMatches": [
{
"User": {
"UserId": "demoUser2",
"UserStatus": "ACTIVE"
},
"Similarity": 99.97946166992188
}
],
"FaceModelVersion": "6"
}