翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
ユーザーの検索 (イメージ)
SearchUsersByImage
は、指定されたイメージ内で検出された最大の顔に一致するユーザーの、指定された CollectionID を、コレクション内で検索します。デフォルトでは、 は類似度スコアが 80% を超える UserIDs SearchUsersByImage を返します。類似度は、UserID が、指定されたイメージで検出された最大の顔とどの程度一致しているかを示します。複数の UserID が返された場合、類似度スコアが高いものから順に一覧表示されます。オプションで、 UserMatchThreshold を使用して別の値を指定できます。詳細については、「Managing users in a collection」を参照してください。
イメージでユーザーを検索するには (SDK)
-
まだ実行していない場合:
-
AmazonRekognitionFullAccess
アクセス権限を持つユーザーを作成または更新します。詳細については、「ステップ 1: AWS アカウントを設定してユーザーを作成する」を参照してください。
-
と AWS SDKsをインストール AWS CLI して設定します。詳細については、「ステップ 2: AWS CLI と AWS SDK をセットアップする」を参照してください。
-
以下の例を使用して、SearchUsersByImage
オペレーションを呼び出します。
- Java
-
この Java の例では、SearchUsersByImage
オペレーションを使用して、入力されたイメージに基づきコレクション内のユーザーを検索します。
import com.amazonaws.services.rekognition.AmazonRekognition;
import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
import com.amazonaws.services.rekognition.model.Image;
import com.amazonaws.services.rekognition.model.S3Object;
import com.amazonaws.services.rekognition.model.SearchUsersByImageRequest;
import com.amazonaws.services.rekognition.model.SearchUsersByImageResult;
import com.amazonaws.services.rekognition.model.UserMatch;
public class SearchUsersByImage {
//Replace bucket, collectionId and photo with your values.
public static final String collectionId = "MyCollection";
public static final String s3Bucket = "bucket";
public static final String s3PhotoFileKey = "input.jpg";
public static void main(String[] args) throws Exception {
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
// Get an image object from S3 bucket.
Image image = new Image()
.withS3Object(new S3Object()
.withBucket(s3Bucket)
.withName(s3PhotoFileKey));
// Search collection for users similar to the largest face in the image.
SearchUsersByImageRequest request = new SearchUsersByImageRequest()
.withCollectionId(collectionId)
.withImage(image)
.withUserMatchThreshold(70F)
.withMaxUsers(2);
SearchUsersByImageResult result =
rekognitionClient.searchUsersByImage(request);
System.out.println("Printing search result with matched user and similarity score");
for (UserMatch match: result.getUserMatches()) {
System.out.println(match.getUser().getUserId() + " with similarity score " + match.getSimilarity());
}
}
}
- AWS CLI
-
この AWS CLI コマンドは、 SearchUsersByImage
オペレーションを使用して、入力イメージに基づいてコレクション内のユーザーを検索します。
aws rekognition search-users-by-image --image '{"S3Object":{"Bucket":"s3BucketName
","Name":"file-name
"}}' --collection-id MyCollectionId
--region region-name
- Python
-
次の例では、SearchUsersByImage
オペレーションを使用して、入力されたイメージに基づきコレクション内のユーザーを検索します。
# 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
import os
logger = logging.getLogger(__name__)
session = boto3.Session(profile_name='profile-name')
client = session.client('rekognition')
def load_image(file_name):
"""
helper function to load the image for indexFaces call from local disk
:param image_file_name: The image file location that will be used by indexFaces call.
:return: The Image in bytes
"""
print(f'- loading image: {file_name}')
with open(file_name, 'rb') as file:
return {'Bytes': file.read()}
def search_users_by_image(collection_id, image_file):
"""
SearchUsersByImage operation with user ID provided as the search source
:param collection_id: The ID of the collection where user and faces are stored.
:param image_file: The image that contains the reference face to search for.
:return: response of SearchUsersByImage API
"""
logger.info(f'Searching for users using an image: {image_file}')
try:
response = client.search_users_by_image(
CollectionId=collection_id,
Image=load_image(image_file)
)
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 SearchUsersByImage with given image: {image_file}')
raise
else:
print(response)
return response
def main():
collection_id = "collection-id"
IMAGE_SEARCH_SOURCE = os.getcwd() + '/image_path'
search_users_by_image(collection_id, IMAGE_SEARCH_SOURCE)
if __name__ == "__main__":
main()
SearchUsersByImage オペレーションリクエスト
SearchUsersByImage
のリクエストには、検索先のコレクションとソースイメージの場所が含まれます。次の例では、ソースイメージは Amazon S3 バケット (S3Object
) に保存されています。また、返されるユーザーの最大数 (MaxUsers
) と、ユーザーを返すために一致する必要がある最小限の信頼度 (UserMatchThreshold
) も指定されています。
{
"CollectionId": "MyCollection",
"Image": {
"S3Object": {
"Bucket": "bucket",
"Name": "input.jpg"
}
},
"MaxUsers": 2,
"UserMatchThreshold": 99
}
SearchUsersByImage オペレーションレスポンス
のレスポンスSearchUsersByImage
には、 の FaceDetail
オブジェクトとSearchedFace
、UserStatus
それぞれ UserId
、、Similarity
および UserMatches を含む のリストが含まれます。入力イメージに複数の顔が含まれている場合、 のリストも返 UnsearchedFaces されます。
{
"SearchedFace": {
"FaceDetail": {
"BoundingBox": {
"Width": 0.23692893981933594,
"Top": 0.19235000014305115,
"Left": 0.39177176356315613,
"Height": 0.5437348484992981
}
}
},
"UserMatches": [
{
"User": {
"UserId": "demoUser1",
"UserStatus": "ACTIVE"
},
"Similarity": 100.0
},
{
"User": {
"UserId": "demoUser2",
"UserStatus": "ACTIVE"
},
"Similarity": 99.97946166992188
}
],
"FaceModelVersion": "6",
"UnsearchedFaces": [
{
"FaceDetails": {
"BoundingBox": {
"Width": 0.031677018851041794,
"Top": 0.5593535900115967,
"Left": 0.6102562546730042,
"Height": 0.0682177022099495
}
},
"Reasons": [
"FACE_NOT_LARGEST"
]
},
{
"FaceDetails": {
"BoundingBox": {
"Width": 0.03254449740052223,
"Top": 0.6080358028411865,
"Left": 0.516062319278717,
"Height": 0.06347997486591339
}
},
"Reasons": [
"FACE_NOT_LARGEST"
]
}
]
}