다음과 SearchFaces 함께 사용하십시오. AWS SDK또는 CLI - Amazon Rekognition

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

다음과 SearchFaces 함께 사용하십시오. AWS SDK또는 CLI

다음 코드 예제는 SearchFaces의 사용 방법을 보여 줍니다.

자세한 내용은 얼굴(얼굴 ID) 검색을 참조하세요.

.NET
AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to find faces in an image that /// match the face Id provided in the method request. /// </summary> public class SearchFacesMatchingId { public static async Task Main() { string collectionId = "MyCollection"; string faceId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; var rekognitionClient = new AmazonRekognitionClient(); // Search collection for faces matching the face id. var searchFacesRequest = new SearchFacesRequest { CollectionId = collectionId, FaceId = faceId, FaceMatchThreshold = 70F, MaxFaces = 2, }; SearchFacesResponse searchFacesResponse = await rekognitionClient.SearchFacesAsync(searchFacesRequest); Console.WriteLine("Face matching faceId " + faceId); Console.WriteLine("Matche(s): "); searchFacesResponse.FaceMatches.ForEach(face => { Console.WriteLine($"FaceId: {face.Face.FaceId} Similarity: {face.Similarity}"); }); } }
  • 자세한 API 내용은 SearchFaces을 참조하십시오. AWS SDK for .NET API참조.

CLI
AWS CLI

모음에서 얼굴 ID와 일치하는 얼굴을 검색하는 방법

다음 search-faces 명령은 모음에서 지정된 얼굴 ID와 일치하는 얼굴을 검색합니다.

aws rekognition search-faces \ --face-id 8d3cfc70-4ba8-4b36-9644-90fba29c2dac \ --collection-id MyCollection

출력:

{ "SearchedFaceId": "8d3cfc70-4ba8-4b36-9644-90fba29c2dac", "FaceModelVersion": "3.0", "FaceMatches": [ { "Face": { "BoundingBox": { "Width": 0.48166701197624207, "Top": 0.20999999344348907, "Left": 0.21250000596046448, "Height": 0.36125001311302185 }, "FaceId": "bd4ceb4d-9acc-4ab7-8ef8-1c2d2ba0a66a", "ExternalImageId": "image1.jpg", "Confidence": 99.99949645996094, "ImageId": "5e1a7588-e5a0-5ee3-bd00-c642518dfe3a" }, "Similarity": 99.30997467041016 }, { "Face": { "BoundingBox": { "Width": 0.18562500178813934, "Top": 0.1618019938468933, "Left": 0.5575000047683716, "Height": 0.24770599603652954 }, "FaceId": "ce7ed422-2132-4a11-ab14-06c5c410f29f", "ExternalImageId": "example-image.jpg", "Confidence": 99.99340057373047, "ImageId": "8d67061e-90d2-598f-9fbd-29c8497039c0" }, "Similarity": 99.24862670898438 }, { "Face": { "BoundingBox": { "Width": 0.18562500178813934, "Top": 0.1618019938468933, "Left": 0.5575000047683716, "Height": 0.24770599603652954 }, "FaceId": "13692fe4-990a-4679-b14a-5ac23d135eab", "ExternalImageId": "image3.jpg", "Confidence": 99.99340057373047, "ImageId": "8df18239-9ad1-5acd-a46a-6581ff98f51b" }, "Similarity": 99.24862670898438 }, { "Face": { "BoundingBox": { "Width": 0.5349419713020325, "Top": 0.29124999046325684, "Left": 0.16389399766921997, "Height": 0.40187498927116394 }, "FaceId": "745f7509-b1fa-44e0-8b95-367b1359638a", "ExternalImageId": "image9.jpg", "Confidence": 99.99979400634766, "ImageId": "67a34327-48d1-5179-b042-01e52ccfeada" }, "Similarity": 96.73158264160156 }, { "Face": { "BoundingBox": { "Width": 0.5307819843292236, "Top": 0.2862499952316284, "Left": 0.1564060002565384, "Height": 0.3987500071525574 }, "FaceId": "2eb5f3fd-e2a9-4b1c-a89f-afa0a518fe06", "ExternalImageId": "image10.jpg", "Confidence": 99.99970245361328, "ImageId": "3c314792-197d-528d-bbb6-798ed012c150" }, "Similarity": 96.48291015625 }, { "Face": { "BoundingBox": { "Width": 0.5074880123138428, "Top": 0.3774999976158142, "Left": 0.18302799761295319, "Height": 0.3812499940395355 }, "FaceId": "086261e8-6deb-4bc0-ac73-ab22323cc38d", "ExternalImageId": "image6.jpg", "Confidence": 99.99930572509766, "ImageId": "ae1593b0-a8f6-5e24-a306-abf529e276fa" }, "Similarity": 96.43287658691406 }, { "Face": { "BoundingBox": { "Width": 0.5574039816856384, "Top": 0.37187498807907104, "Left": 0.14559100568294525, "Height": 0.4181250035762787 }, "FaceId": "11c4bd3c-19c5-4eb8-aecc-24feb93a26e1", "ExternalImageId": "image5.jpg", "Confidence": 99.99960327148438, "ImageId": "80739b4d-883f-5b78-97cf-5124038e26b9" }, "Similarity": 95.25305938720703 }, { "Face": { "BoundingBox": { "Width": 0.5773710012435913, "Top": 0.34437501430511475, "Left": 0.12396000325679779, "Height": 0.4337500035762787 }, "FaceId": "57189455-42b0-4839-a86c-abda48b13174", "ExternalImageId": "image8.jpg", "Confidence": 100.0, "ImageId": "0aff2f37-e7a2-5dbc-a3a3-4ef6ec18eaa0" }, "Similarity": 95.22837829589844 } ] }

자세한 내용은 Amazon Rekognition 개발자 안내서의 얼굴 ID를 사용하여 얼굴 검색을 참조하세요.

  • 자세한 API 내용은 SearchFaces을 참조하십시오. AWS CLI 명령 참조.

Java
SDK자바 2.x의 경우
참고

더 많은 내용이 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import software.amazon.awssdk.services.rekognition.model.SearchFacesByImageRequest; import software.amazon.awssdk.services.rekognition.model.Image; import software.amazon.awssdk.services.rekognition.model.SearchFacesByImageResponse; import software.amazon.awssdk.services.rekognition.model.FaceMatch; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.List; /** * 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 SearchFaceMatchingImageCollection { public static void main(String[] args) { final String usage = """ Usage: <collectionId> <sourceImage> Where: collectionId - The id of the collection. \s sourceImage - The path to the image (for example, C:\\AWS\\pic1.png).\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String collectionId = args[0]; String sourceImage = args[1]; Region region = Region.US_EAST_1; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .build(); System.out.println("Searching for a face in a collections"); searchFaceInCollection(rekClient, collectionId, sourceImage); rekClient.close(); } public static void searchFaceInCollection(RekognitionClient rekClient, String collectionId, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); Image souImage = Image.builder() .bytes(sourceBytes) .build(); SearchFacesByImageRequest facesByImageRequest = SearchFacesByImageRequest.builder() .image(souImage) .maxFaces(10) .faceMatchThreshold(70F) .collectionId(collectionId) .build(); SearchFacesByImageResponse imageResponse = rekClient.searchFacesByImage(facesByImageRequest); System.out.println("Faces matching in the collection"); List<FaceMatch> faceImageMatches = imageResponse.faceMatches(); for (FaceMatch face : faceImageMatches) { System.out.println("The similarity level is " + face.similarity()); System.out.println(); } } catch (RekognitionException | FileNotFoundException e) { System.out.println(e.getMessage()); System.exit(1); } } }
  • 자세한 API 내용은 SearchFaces을 참조하십시오. AWS SDK for Java 2.x API참조.

Python
SDK파이썬용 (보토3)
참고

더 많은 정보가 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

class RekognitionCollection: """ Encapsulates an Amazon Rekognition collection. This class is a thin wrapper around parts of the Boto3 Amazon Rekognition API. """ def __init__(self, collection, rekognition_client): """ Initializes a collection object. :param collection: Collection data in the format returned by a call to create_collection. :param rekognition_client: A Boto3 Rekognition client. """ self.collection_id = collection["CollectionId"] self.collection_arn, self.face_count, self.created = self._unpack_collection( collection ) self.rekognition_client = rekognition_client @staticmethod def _unpack_collection(collection): """ Unpacks optional parts of a collection that can be returned by describe_collection. :param collection: The collection data. :return: A tuple of the data in the collection. """ return ( collection.get("CollectionArn"), collection.get("FaceCount", 0), collection.get("CreationTimestamp"), ) def search_faces(self, face_id, threshold, max_faces): """ Searches for faces in the collection that match another face from the collection. :param face_id: The ID of the face in the collection to search for. :param threshold: The match confidence must be greater than this value for a face to be included in the results. :param max_faces: The maximum number of faces to return. :return: The list of matching faces found in the collection. This list does not contain the face specified by `face_id`. """ try: response = self.rekognition_client.search_faces( CollectionId=self.collection_id, FaceId=face_id, FaceMatchThreshold=threshold, MaxFaces=max_faces, ) faces = [RekognitionFace(face["Face"]) for face in response["FaceMatches"]] logger.info( "Found %s faces in %s that match %s.", len(faces), self.collection_id, face_id, ) except ClientError: logger.exception( "Couldn't search for faces in %s that match %s.", self.collection_id, face_id, ) raise else: return faces
  • 자세한 API 내용은 SearchFaces을 참조하십시오. AWS SDK파이썬 (Boto3) API 참조용.

전체 목록은 다음과 같습니다. AWS SDK개발자 가이드 및 코드 예제는 을 참조하십시오Rekognition과 함께 사용하기 AWS SDK. 이 항목에는 시작에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.