사용자 검색(이미지) - Amazon Rekognition

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

사용자 검색(이미지)

SearchUsersByImage는 지정된 CollectionID를 검색하여 제공된 이미지에서 감지된 가장 큰 얼굴과 일치하는 컬렉션의 사용자를 찾습니다. 기본적으로 SearchUsersByImage는 유사성 점수가 80%를 초과하는 UserID를 반환합니다. 유사성은 UserID가 제공된 이미지에서 감지된 가장 큰 얼굴과 얼마나 가깝게 일치하는지를 나타냅니다. 여러 UserID가 반환되는 경우 유사성 점수가 높은 것부터 가장 낮은 순으로 나열됩니다. 필요하다면 UserMatchThreshold를 사용하여 다른 값을 지정할 수 있습니다. 자세한 내용은 컬렉션의 사용자 관리 단원을 참조하십시오.

이미지로 사용자 검색하기(SDK)
  1. 아직 설정하지 않았다면 다음과 같이 하세요.

    1. AmazonRekognitionFullAccess 권한이 있는 사용자를 생성하거나 업데이트합니다. 자세한 내용은 1단계: AWS 계정 설정 및 사용자 생성 단원을 참조하십시오.

    2. AWS CLI 및 AWS SDKs를 설치하고 구성합니다. 자세한 내용은 2단계: AWS CLI 및 AWS SDKs 설정 단원을 참조하십시오.

  2. 다음 예제를 사용하여 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에 대한 응답에는 SearchedFace에 대한 FaceDetail 개체와 UserMatches 목록 및 각각의 UserId, Similarity, 그리고 UserStatus가 포함됩니다. 입력 이미지에 얼굴이 두 개 이상 포함된 경우 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" ] } ] }