翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
コレクションからの顔の削除
DeleteFaces オペレーションを使用すると、コレクションから顔を削除できます。詳細については、「コレクション内の顔の管理」を参照してください。
コレクションから顔を削除するには
-
まだ実行していない場合:
-
AmazonRekognitionFullAccess
アクセス権限を持つユーザーを作成または更新します。詳細については、「ステップ 1: AWS アカウントを設定してユーザーを作成する」を参照してください。
-
および AWS SDKs をインストール AWS CLI して設定します。詳細については、「ステップ 2: AWS CLI と AWS SDK をセットアップする」を参照してください。
-
以下の例を使用して、DeleteFaces
オペレーションを呼び出します。
- Java
-
この例では、コレクションから 1 つの顔を削除します。
collectionId
の値は、削除する顔が含まれているコレクションに変更します。faces
の値は、削除する顔の ID に変更します。複数の顔を削除するには、顔 ID を faces
配列に追加します。
//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.DeleteFacesRequest;
import com.amazonaws.services.rekognition.model.DeleteFacesResult;
import java.util.List;
public class DeleteFacesFromCollection {
public static final String collectionId = "MyCollection";
public static final String faces[] = {"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"};
public static void main(String[] args) throws Exception {
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
DeleteFacesRequest deleteFacesRequest = new DeleteFacesRequest()
.withCollectionId(collectionId)
.withFaceIds(faces);
DeleteFacesResult deleteFacesResult=rekognitionClient.deleteFaces(deleteFacesRequest);
List < String > faceRecords = deleteFacesResult.getDeletedFaces();
System.out.println(Integer.toString(faceRecords.size()) + " face(s) deleted:");
for (String face: faceRecords) {
System.out.println("FaceID: " + face);
}
}
}
- Java V2
-
このコードは、 AWS Documentation SDK サンプル GitHub リポジトリから取得されます。詳しい事例はこちらです。
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.DeleteFacesRequest;
import software.amazon.awssdk.services.rekognition.model.RekognitionException;
// snippet-end:[rekognition.java2.delete_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 DeleteFacesFromCollection {
public static void main(String[] args) {
final String usage = "\n" +
"Usage: " +
" <collectionId> <faceId> \n\n" +
"Where:\n" +
" collectionId - The id of the collection from which faces are deleted. \n\n" +
" faceId - The id of the face to delete. \n\n";
if (args.length != 1) {
System.out.println(usage);
System.exit(1);
}
String collectionId = args[0];
String faceId = args[1];
Region region = Region.US_EAST_1;
RekognitionClient rekClient = RekognitionClient.builder()
.region(region)
.credentialsProvider(ProfileCredentialsProvider.create("profile-name"))
.build();
System.out.println("Deleting collection: " + collectionId);
deleteFacesCollection(rekClient, collectionId, faceId);
rekClient.close();
}
// snippet-start:[rekognition.java2.delete_faces_collection.main]
public static void deleteFacesCollection(RekognitionClient rekClient,
String collectionId,
String faceId) {
try {
DeleteFacesRequest deleteFacesRequest = DeleteFacesRequest.builder()
.collectionId(collectionId)
.faceIds(faceId)
.build();
rekClient.deleteFaces(deleteFacesRequest);
System.out.println("The face was deleted from the collection.");
} catch(RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
// snippet-end:[rekognition.java2.delete_faces_collection.main]
}
- AWS CLI
-
この AWS CLI コマンドは、 CLI オペレーションの JSON delete-faces
出力を表示します。collection-id
の値は、削除する顔が含まれているコレクションの名前に置き換えます。face-ids
の値は、削除する顔 ID の配列に置き換えます。Rekognition セッションを作成する行の profile_name
の値を、自分のデベロッパープロファイル名に置き換えます。
aws rekognition delete-faces --collection-id "collection-id" --face-ids "faceid" --profile profile-name
- Python
-
この例では、コレクションから 1 つの顔を削除します。
collectionId
の値は、削除する顔が含まれているコレクションに変更します。faces
の値は、削除する顔の ID に変更します。複数の顔を削除するには、顔 ID を faces
配列に追加します。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 delete_faces_from_collection(collection_id, faces):
session = boto3.Session(profile_name='profile-name')
client = session.client('rekognition')
response = client.delete_faces(CollectionId=collection_id,
FaceIds=faces)
print(str(len(response['DeletedFaces'])) + ' faces deleted:')
for faceId in response['DeletedFaces']:
print(faceId)
return len(response['DeletedFaces'])
def main():
collection_id = 'collection-id'
faces = []
faces.append("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
faces_count = delete_faces_from_collection(collection_id, faces)
print("deleted faces count: " + str(faces_count))
if __name__ == "__main__":
main()
- .NET
-
この例では、コレクションから 1 つの顔を削除します。
collectionId
の値は、削除する顔が含まれているコレクションに変更します。faces
の値は、削除する顔の ID に変更します。複数の顔を削除するには、顔 ID を faces
リストに追加します。
//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 System.Collections.Generic;
using Amazon.Rekognition;
using Amazon.Rekognition.Model;
public class DeleteFaces
{
public static void Example()
{
String collectionId = "MyCollection";
List<String> faces = new List<String>() { "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" };
AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();
DeleteFacesRequest deleteFacesRequest = new DeleteFacesRequest()
{
CollectionId = collectionId,
FaceIds = faces
};
DeleteFacesResponse deleteFacesResponse = rekognitionClient.DeleteFaces(deleteFacesRequest);
foreach (String face in deleteFacesResponse.DeletedFaces)
Console.WriteLine("FaceID: " + face);
}
}
DeleteFaces オペレーションのリクエスト
DeleteFaces
への入力は、顔が含まれているコレクションの ID と、削除する顔の ID の配列です。
{
"CollectionId": "MyCollection",
"FaceIds": [
"daf29cac-f910-41e9-851f-6eeb0e08f973"
]
}
DeleteFaces オペレーションのレスポンス
DeleteFaces
レスポンスは、削除した顔の ID の配列を返します。
{
"DeletedFaces": [
"daf29cac-f910-41e9-851f-6eeb0e08f973"
]
}
入力時に指定した顔 ID が、現在特定のユーザーに関連付けられている場合は、正当な理由と共に UnsuccessfulFaceDeletions の一部として返されます。
{
"DeletedFaces": [
"daf29cac-f910-41e9-851f-6eeb0e08f973"
],
"UnsuccessfulFaceDeletions" : [
{
"FaceId" : "0b683aed-a0f1-48b2-9b5e-139e9cc2a757",
"UserId" : "demoUser1",
"Reason" : ["ASSOCIATED_TO_AN_EXISTING_USER"]
}
]
}