Gunakan DeleteFaces dengan AWS SDK atau CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan DeleteFaces dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanDeleteFaces.

Untuk informasi selengkapnya, lihat Menghapus wajah dari koleksi.

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

using System; using System.Collections.Generic; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to delete one or more faces from /// a Rekognition collection. /// </summary> public class DeleteFaces { public static async Task Main() { string collectionId = "MyCollection"; var faces = new List<string> { "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }; var rekognitionClient = new AmazonRekognitionClient(); var deleteFacesRequest = new DeleteFacesRequest() { CollectionId = collectionId, FaceIds = faces, }; DeleteFacesResponse deleteFacesResponse = await rekognitionClient.DeleteFacesAsync(deleteFacesRequest); deleteFacesResponse.DeletedFaces.ForEach(face => { Console.WriteLine($"FaceID: {face}"); }); } }
  • Untuk API detailnya, lihat DeleteFacesdi AWS SDK for .NET APIReferensi.

CLI
AWS CLI

Untuk menghapus wajah dari koleksi

delete-facesPerintah berikut menghapus wajah yang ditentukan dari koleksi.

aws rekognition delete-faces \ --collection-id MyCollection --face-ids '["0040279c-0178-436e-b70a-e61b074e96b0"]'

Output:

{ "DeletedFaces": [ "0040279c-0178-436e-b70a-e61b074e96b0" ] }

Untuk informasi selengkapnya, lihat Menghapus Wajah dari Koleksi di Panduan Pengembang Rekognition Amazon.

  • Untuk API detailnya, lihat DeleteFacesdi Referensi AWS CLI Perintah.

Java
SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

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; /** * 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 = """ Usage: <collectionId> <faceId>\s Where: collectionId - The id of the collection from which faces are deleted.\s faceId - The id of the face to delete.\s """; 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) .build(); System.out.println("Deleting collection: " + collectionId); deleteFacesCollection(rekClient, collectionId, faceId); rekClient.close(); } 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); } } }
  • Untuk API detailnya, lihat DeleteFacesdi AWS SDK for Java 2.x APIReferensi.

Kotlin
SDKuntuk Kotlin
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

suspend fun deleteFacesCollection( collectionIdVal: String?, faceIdVal: String, ) { val deleteFacesRequest = DeleteFacesRequest { collectionId = collectionIdVal faceIds = listOf(faceIdVal) } RekognitionClient { region = "us-east-1" }.use { rekClient -> rekClient.deleteFaces(deleteFacesRequest) println("$faceIdVal was deleted from the collection") } }
Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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 delete_faces(self, face_ids): """ Deletes faces from the collection. :param face_ids: The list of IDs of faces to delete. :return: The list of IDs of faces that were deleted. """ try: response = self.rekognition_client.delete_faces( CollectionId=self.collection_id, FaceIds=face_ids ) deleted_ids = response["DeletedFaces"] logger.info( "Deleted %s faces from %s.", len(deleted_ids), self.collection_id ) except ClientError: logger.exception("Couldn't delete faces from %s.", self.collection_id) raise else: return deleted_ids
  • Untuk API detailnya, lihat DeleteFaces AWSSDKReferensi Python (Boto3). API