Auflisten von Sammlungen - Amazon Rekognition

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Auflisten von Sammlungen

Sie können den ListCollectionsVorgang verwenden, um die Sammlungen in der Region aufzulisten, die Sie verwenden.

Weitere Informationen finden Sie unter Verwalten von Sammlungen.

Sie können Sammlungen auflisten (SDK)
  1. Wenn Sie dies noch nicht getan haben:

    1. Erstellen oder aktualisieren Sie einen Benutzer mit AmazonRekognitionFullAccess-Berechtigungen. Weitere Informationen finden Sie unter Schritt 1: Einrichten eines AWS-Kontos und Erstellen eines Benutzers.

    2. Installieren und konfigurieren Sie die AWS CLI und die AWS SDKs. Weitere Informationen finden Sie unter Schritt 2: Richten Sie die AWS CLI und AWS SDKs ein.

  2. Verwenden Sie die folgenden Beispiele zum Aufrufen der ListCollections-Operation.

    Java

    Im folgenden Beispiel sind die Sammlungen in der aktuellen Region aufgelistet.

    //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 java.util.List; import com.amazonaws.services.rekognition.AmazonRekognition; import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; import com.amazonaws.services.rekognition.model.ListCollectionsRequest; import com.amazonaws.services.rekognition.model.ListCollectionsResult; public class ListCollections { public static void main(String[] args) throws Exception { AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient(); System.out.println("Listing collections"); int limit = 10; ListCollectionsResult listCollectionsResult = null; String paginationToken = null; do { if (listCollectionsResult != null) { paginationToken = listCollectionsResult.getNextToken(); } ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest() .withMaxResults(limit) .withNextToken(paginationToken); listCollectionsResult=amazonRekognition.listCollections(listCollectionsRequest); List < String > collectionIds = listCollectionsResult.getCollectionIds(); for (String resultId: collectionIds) { System.out.println(resultId); } } while (listCollectionsResult != null && listCollectionsResult.getNextToken() != null); } }
    Java V2

    Dieser Code stammt aus dem AWS Documentation SDK Examples GitHub Repository. Das vollständige Beispiel finden Sie hier.

    //snippet-start:[rekognition.java2.list_collections.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.ListCollectionsRequest; import software.amazon.awssdk.services.rekognition.model.ListCollectionsResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import java.util.List; //snippet-end:[rekognition.java2.list_collections.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 ListCollections { public static void main(String[] args) { Region region = Region.US_EAST_1; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create("profile-name")) .build(); System.out.println("Listing collections"); listAllCollections(rekClient); rekClient.close(); } // snippet-start:[rekognition.java2.list_collections.main] public static void listAllCollections(RekognitionClient rekClient) { try { ListCollectionsRequest listCollectionsRequest = ListCollectionsRequest.builder() .maxResults(10) .build(); ListCollectionsResponse response = rekClient.listCollections(listCollectionsRequest); List<String> collectionIds = response.collectionIds(); for (String resultId : collectionIds) { System.out.println(resultId); } } catch (RekognitionException e) { System.out.println(e.getMessage()); System.exit(1); } } // snippet-end:[rekognition.java2.list_collections.main] }
    AWS CLI

    Dieser AWS CLI Befehl zeigt die JSON-Ausgabe für den list-collections CLI-Vorgang an. Ersetzen Sie den Wert von profile_name mit dem Namen Ihres Entwicklerprofils.

    aws rekognition list-collections --profile profile-name
    Python

    Im folgenden Beispiel sind die Sammlungen in der aktuellen Region aufgelistet.

    Ersetzen Sie den Wert von profile_name in der Zeile, die die Rekognition-Sitzung erstellt, durch den Namen Ihres Entwicklerprofils.

    #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_collections(): max_results=2 client=boto3.client('rekognition') #Display all the collections print('Displaying collections...') response=client.list_collections(MaxResults=max_results) collection_count=0 done=False while done==False: collections=response['CollectionIds'] for collection in collections: print (collection) collection_count+=1 if 'NextToken' in response: nextToken=response['NextToken'] response=client.list_collections(NextToken=nextToken,MaxResults=max_results) else: done=True return collection_count def main(): collection_count=list_collections() print("collections: " + str(collection_count)) if __name__ == "__main__": main()
    .NET

    Im folgenden Beispiel sind die Sammlungen in der aktuellen Region aufgelistet.

    //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 ListCollections { public static void Example() { AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); Console.WriteLine("Listing collections"); int limit = 10; ListCollectionsResponse listCollectionsResponse = null; String paginationToken = null; do { if (listCollectionsResponse != null) paginationToken = listCollectionsResponse.NextToken; ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest() { MaxResults = limit, NextToken = paginationToken }; listCollectionsResponse = rekognitionClient.ListCollections(listCollectionsRequest); foreach (String resultId in listCollectionsResponse.CollectionIds) Console.WriteLine(resultId); } while (listCollectionsResponse != null && listCollectionsResponse.NextToken != null); } }
    Node.js

    Ersetzen Sie den Wert von profile_name in der Zeile, die die Rekognition-Sitzung erstellt, durch den Namen Ihres Entwicklerprofils.

    //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 { ListCollectionsCommand } from "@aws-sdk/client-rekognition"; import { RekognitionClient } from "@aws-sdk/client-rekognition"; import {fromIni} from '@aws-sdk/credential-providers'; // Set the AWS Region. const REGION = "region-name"; //e.g. "us-east-1" // Set the profile name const profileName = "profile-name" // Name the collection const rekogClient = new RekognitionClient({region: REGION, credentials: fromIni({profile: profileName,}), }); const listCollection = async () => { var max_results = 10 console.log("Displaying collections:") var response = await rekogClient.send(new ListCollectionsCommand({MaxResults: max_results})) var collection_count = 0 var done = false while (done == false){ var collections = response.CollectionIds collections.forEach(collection => { console.log(collection) collection_count += 1 }); return collection_count } } var collect_list = await listCollection() console.log(collect_list)

ListCollections Operationsanforderung

Bei der Eingabe in ListCollections handelt es sich um die maximale Anzahl der Sammlungen, die zurückgegeben werden sollen.

{ "MaxResults": 2 }

Wenn die Antwort mehr Sammlungen als von MaxResults angefordert aufweist, wird ein Token zurückgegeben, das Sie verwenden können, um den nächsten Ergebnissatz in einem nachfolgenden Aufruf an ListCollections abzurufen. Beispielsweise:

{ "NextToken": "MGYZLAHX1T5a....", "MaxResults": 2 }

ListCollections Antwort auf die Operation

Amazon Rekognition gibt eine Reihe von Sammlungen zurück (CollectionIds). Ein separates Array (FaceModelVersions) enthält die Version des Gesichtsmodells, die zum Analysieren der Gesichter in der jeweiligen Sammlung verwendet wird. Beispiel: In der folgenden JSON-Antwort analysiert die Sammlung MyCollection Gesichter mit Version 2.0 des Gesichtsmodells. Die Sammlung AnotherCollection nutzt Version 3.0 des Gesichtsmodells. Weitere Informationen finden Sie unter Modellversionsverwaltung.

NextToken ist das Token, das für den Abruf des nächsten Ergebnissatzes in einem nachfolgenden Aufruf an ListCollections verwendet wird.

{ "CollectionIds": [ "MyCollection", "AnotherCollection" ], "FaceModelVersions": [ "2.0", "3.0" ], "NextToken": "MGYZLAHX1T5a...." }