컬렉션의 얼굴 및 연결된 사용자 나열 - Amazon Rekognition

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

컬렉션의 얼굴 및 연결된 사용자 나열

ListFaces작업을 사용하여 컬렉션의 얼굴 및 관련 사용자를 나열할 수 있습니다.

자세한 내용은 컬렉션에서 얼굴 관리 단원을 참조하십시오.

컬렉션에 얼굴을 나열하려면 (SDK)
  1. 아직 설정하지 않았다면 다음과 같이 하세요.

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

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

  2. 다음 예제를 사용하여 ListFaces 작업을 호출합니다.

    Java

    이 예제는 모음의 얼굴 목록을 표시합니다.

    collectionId의 값을 원하는 모음으로 변경합니다.

    //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.) package aws.example.rekognition.image; import com.amazonaws.services.rekognition.AmazonRekognition; import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; import com.amazonaws.services.rekognition.model.Face; import com.amazonaws.services.rekognition.model.ListFacesRequest; import com.amazonaws.services.rekognition.model.ListFacesResult; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; public class ListFacesInCollection { public static final String collectionId = "MyCollection"; public static void main(String[] args) throws Exception { AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); ObjectMapper objectMapper = new ObjectMapper(); ListFacesResult listFacesResult = null; System.out.println("Faces in collection " + collectionId); String paginationToken = null; do { if (listFacesResult != null) { paginationToken = listFacesResult.getNextToken(); } ListFacesRequest listFacesRequest = new ListFacesRequest() .withCollectionId(collectionId) .withMaxResults(1) .withNextToken(paginationToken); listFacesResult = rekognitionClient.listFaces(listFacesRequest); List < Face > faces = listFacesResult.getFaces(); for (Face face: faces) { System.out.println(objectMapper.writerWithDefaultPrettyPrinter() .writeValueAsString(face)); } } while (listFacesResult != null && listFacesResult.getNextToken() != null); } }
    Java V2

    이 코드는 AWS 문서 SDK 예제 GitHub 리포지토리에서 가져온 것입니다. 전체 예제는 여기에서 확인하세요.

    // snippet-start:[rekognition.java2.list_faces_collection.import] import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.Face; import software.amazon.awssdk.services.rekognition.model.ListFacesRequest; import software.amazon.awssdk.services.rekognition.model.ListFacesResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import java.util.List; // snippet-end:[rekognition.java2.list_faces_collection.import] /** * Before running this Java V2 code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListFacesInCollection { public static void main(String[] args) { final String usage = "\n" + "Usage: " + " <collectionId>\n\n" + "Where:\n" + " collectionId - The name of the collection. \n\n"; if (args.length < 1) { System.out.println(usage); System.exit(1); } String collectionId = args[0]; Region region = Region.US_EAST_1; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create("profile-name")) .build(); System.out.println("Faces in collection " + collectionId); listFacesCollection(rekClient, collectionId) ; rekClient.close(); } // snippet-start:[rekognition.java2.list_faces_collection.main] public static void listFacesCollection(RekognitionClient rekClient, String collectionId ) { try { ListFacesRequest facesRequest = ListFacesRequest.builder() .collectionId(collectionId) .maxResults(10) .build(); ListFacesResponse facesResponse = rekClient.listFaces(facesRequest); List<Face> faces = facesResponse.faces(); for (Face face: faces) { System.out.println("Confidence level there is a face: "+face.confidence()); System.out.println("The face Id value is "+face.faceId()); } } catch (RekognitionException e) { System.out.println(e.getMessage()); System.exit(1); } } // snippet-end:[rekognition.java2.list_faces_collection.main] }
    AWS CLI

    이 AWS CLI 명령은 list-faces CLI 작업에 대한 JSON 출력을 표시합니다. collection-id의 값을, 목록을 조회할 모음의 이름으로 바꿉니다. Rekognition 세션을 생성하는 라인에서 profile_name의 값을 개발자 프로필의 이름으로 대체합니다.

    aws rekognition list-faces --collection-id "collection-id" --profile profile-name
    Python

    이 예제는 모음의 얼굴 목록을 표시합니다.

    Rekognition 세션을 생성하는 라인에서 profile_name의 값을 개발자 프로필의 이름으로 대체합니다.

    # 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 def list_faces_in_collection(collection_id): maxResults = 2 faces_count = 0 tokens = True session = boto3.Session(profile_name='profile-name') client = session.client('rekognition') response = client.list_faces(CollectionId=collection_id, MaxResults=maxResults) print('Faces in collection ' + collection_id) while tokens: faces = response['Faces'] for face in faces: print(face) faces_count += 1 if 'NextToken' in response: nextToken = response['NextToken'] response = client.list_faces(CollectionId=collection_id, NextToken=nextToken, MaxResults=maxResults) else: tokens = False return faces_count def main(): collection_id = 'collection-id' faces_count = list_faces_in_collection(collection_id) print("faces count: " + str(faces_count)) if __name__ == "__main__": main()
    .NET

    이 예제는 모음의 얼굴 목록을 표시합니다.

    collectionId의 값을 원하는 모음으로 변경합니다.

    //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.) using System; using Amazon.Rekognition; using Amazon.Rekognition.Model; public class ListFaces { public static void Example() { String collectionId = "MyCollection"; AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); ListFacesResponse listFacesResponse = null; Console.WriteLine("Faces in collection " + collectionId); String paginationToken = null; do { if (listFacesResponse != null) paginationToken = listFacesResponse.NextToken; ListFacesRequest listFacesRequest = new ListFacesRequest() { CollectionId = collectionId, MaxResults = 1, NextToken = paginationToken }; listFacesResponse = rekognitionClient.ListFaces(listFacesRequest); foreach(Face face in listFacesResponse.Faces) Console.WriteLine(face.FaceId); } while (listFacesResponse != null && !String.IsNullOrEmpty(listFacesResponse.NextToken)); } }

ListFaces 작업 요청

ListFaces에 대한 입력은 얼굴 목록을 조회하려는 모음의 ID입니다. MaxResults는 반환할 최대 얼굴 수입니다. ListFaces 또한 결과를 IDs 필터링할 때 사용할 얼굴 목록을 가져오고, 제공된 사용자 ID는 해당 사용자와 관련된 얼굴만 나열합니다.

{ "CollectionId": "MyCollection", "MaxResults": 1 }

응답의 얼굴이, MaxResults가 요청한 것보다 많으면 후속 ListFaces 호출에서 다음 결과 집합을 가져오는 데 사용할 수 있는 토큰이 반환됩니다. 예:

{ "CollectionId": "MyCollection", "NextToken": "sm+5ythT3aeEVIR4WA....", "MaxResults": 1 }

ListFaces 오퍼레이션 응답

ListFaces의 응답은 지정한 모음에 저장된 얼굴 메타데이터에 대한 정보입니다.

  • FaceModelVersion— 컬렉션과 관련된 얼굴 모델 버전. 자세한 내용은 모델 버전 관리에 대한 이해 단원을 참조하십시오.

  • Faces – 컬렉션에 있는 얼굴에 대한 정보입니다. 여기에는 신뢰도 BoundingBox, 이미지 식별자, 얼굴 ID에 대한 정보가 포함됩니다. 자세한 내용은 Face를 참조하십시오.

  • NextToken— 다음 결과 세트를 얻는 데 사용되는 토큰.

{ "FaceModelVersion": "6.0", "Faces": [ { "Confidence": 99.76940155029297, "IndexFacesModelVersion": "6.0", "UserId": "demoUser2", "ImageId": "56a0ca74-1c83-39dd-b363-051a64168a65", "BoundingBox": { "Width": 0.03177810087800026, "Top": 0.36568498611450195, "Left": 0.3453829884529114, "Height": 0.056759100407361984 }, "FaceId": "c92265d4-5f9c-43af-a58e-12be0ce02bc3" }, { "BoundingBox": { "Width": 0.03254450112581253, "Top": 0.6080359816551208, "Left": 0.5160620212554932, "Height": 0.06347999721765518 }, "IndexFacesModelVersion": "6.0", "FaceId": "851cb847-dccc-4fea-9309-9f4805967855", "Confidence": 99.94369506835938, "ImageId": "a8aed589-ceec-35f7-9c04-82e0b546b024" }, { "BoundingBox": { "Width": 0.03094629943370819, "Top": 0.4218429923057556, "Left": 0.6513839960098267, "Height": 0.05266290158033371 }, "IndexFacesModelVersion": "6.0", "FaceId": "c0eb3b65-24a0-41e1-b23a-1908b1aaeac1", "Confidence": 99.82969665527344, "ImageId": "56a0ca74-1c83-39dd-b363-051a64168a65" } ] }