本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
可以使用 SearchFaces 操作來搜尋集合中符合指定映像中最大人臉的人臉。
當偵測到人臉並加入至集合時,人臉 ID 將隨 IndexFaces 操作的回應一同回傳。如需詳細資訊,請參閱 管理集合中的人臉。
若要使用人臉 ID 來搜尋集合中的人臉 (SDK)
-
如果您尚未執行:
-
建立或更新具有
AmazonRekognitionFullAccess
許可的使用者。如需詳細資訊,請參閱步驟 1:設定 AWS 帳戶並建立使用者。 -
安裝和設定 AWS CLI 和 AWS SDKs。如需詳細資訊,請參閱步驟 2:設定 AWS CLI 和 SDK AWS SDKs。
-
-
使用下列範例來呼叫
SearchFaces
操作。此範例顯示有關與由其 ID 識別的人臉符合的人臉資訊。
將
collectionID
的值變更為包含所需人臉的集合。將faceId
的值變更為要尋找的人臉識別符。//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.fasterxml.jackson.databind.ObjectMapper; import com.amazonaws.services.rekognition.model.FaceMatch; import com.amazonaws.services.rekognition.model.SearchFacesRequest; import com.amazonaws.services.rekognition.model.SearchFacesResult; import java.util.List; public class SearchFaceMatchingIdCollection { public static final String collectionId = "MyCollection"; public static final String faceId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; public static void main(String[] args) throws Exception { AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); ObjectMapper objectMapper = new ObjectMapper(); // Search collection for faces matching the face id. SearchFacesRequest searchFacesRequest = new SearchFacesRequest() .withCollectionId(collectionId) .withFaceId(faceId) .withFaceMatchThreshold(70F) .withMaxFaces(2); SearchFacesResult searchFacesByIdResult = rekognitionClient.searchFaces(searchFacesRequest); System.out.println("Face matching faceId " + faceId); List < FaceMatch > faceImageMatches = searchFacesByIdResult.getFaceMatches(); for (FaceMatch face: faceImageMatches) { System.out.println(objectMapper.writerWithDefaultPrettyPrinter() .writeValueAsString(face)); System.out.println(); } } }
執行程式碼範例。顯示有關人臉符合的資訊。
SearchFaces 操作要求
SearchFaces
將根據人臉 ID (每個儲存在人臉集合中的人臉都有人臉 ID) 在指定的人臉集合中搜尋相似的人臉。回應不包含您要搜尋的臉部。它只包含類似的臉部。在預設情況下,SearchFaces
傳回在使用演算法偵測後相似度超過 80% 的人臉。相似度代表偵測到的人臉與輸入人臉間符合的程度。或者,可以使用 FaceMatchThreshold
來指定不同的值。
{
"CollectionId": "MyCollection",
"FaceId": "0b683aed-a0f1-48b2-9b5e-139e9cc2a757",
"MaxFaces": 2,
"FaceMatchThreshold": 99
}
SearchFaces 操作回應
此操作會傳回一系列找到的人臉配對以及您提供的人臉 ID 來做為輸入檔。
{ "SearchedFaceId": "7ecf8c19-5274-5917-9c91-1db9ae0449e2", "FaceMatches": [
list of face matches found
] }
對於每個找到的臉部配對,回應將包含相似度以及臉部中繼資料,如下方範例回應所示:
{
...
"FaceMatches": [
{
"Similarity": 100.0,
"Face": {
"BoundingBox": {
"Width": 0.6154,
"Top": 0.2442,
"Left": 0.1765,
"Height": 0.4692
},
"FaceId": "84de1c86-5059-53f2-a432-34ebb704615d",
"Confidence": 99.9997,
"ImageId": "d38ebf91-1a11-58fc-ba42-f978b3f32f60"
}
},
{
"Similarity": 84.6859,
"Face": {
"BoundingBox": {
"Width": 0.2044,
"Top": 0.2254,
"Left": 0.4622,
"Height": 0.3119
},
"FaceId": "6fc892c7-5739-50da-a0d7-80cc92c0ba54",
"Confidence": 99.9981,
"ImageId": "5d913eaf-cf7f-5e09-8c8f-cb1bdea8e6aa"
}
}
]
}