翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
コレクションの作成
コレクションは、CreateCollection オペレーションで作成できます。
詳細については、「コレクションの管理」を参照してください。
コレクションを作成するには (SDK)
まだ実行していない場合:
を使用して IAM ユーザーを作成または更新する
AmazonRekognitionFullAccess
アクセス許可。詳細については、「ステップ 1: AWS アカウントをセットアップし、IAM ユーザーを作成します。」を参照してください。AWS CLI と AWS SDK をインストールして設定します。詳細については、「ステップ 2: をセットアップするAWS CLIそしてAWSSDK」を参照してください。
-
以下の例を使用して、
CreateCollection
オペレーションを呼び出します。- Java
-
次の例では、コレクションを作成して、その Amazon リソースネーム (ARN) を表示します。
collectionId
の値は、作成するコレクションの名前に変更します。//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.CreateCollectionRequest; import com.amazonaws.services.rekognition.model.CreateCollectionResult; public class CreateCollection { public static void main(String[] args) throws Exception { AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); String collectionId = "MyCollection"; System.out.println("Creating collection: " + collectionId ); CreateCollectionRequest request = new CreateCollectionRequest() .withCollectionId(collectionId); CreateCollectionResult createCollectionResult = rekognitionClient.createCollection(request); System.out.println("CollectionArn : " + createCollectionResult.getCollectionArn()); System.out.println("Status code : " + createCollectionResult.getStatusCode().toString()); } }
- Java V2
-
このコードはAWSドキュメント SDK の例 GitHub リポジトリ。完全な例を見るここに
。 public static void createMyCollection(RekognitionClient rekClient,String collectionId ) { try { CreateCollectionRequest collectionRequest = CreateCollectionRequest.builder() .collectionId(collectionId) .build(); CreateCollectionResponse collectionResponse = rekClient.createCollection(collectionRequest); System.out.println("CollectionArn : " + collectionResponse.collectionArn()); System.out.println("Status code : " + collectionResponse.statusCode().toString()); } catch(RekognitionException e) { System.out.println(e.getMessage()); System.exit(1); } }
- AWS CLI
-
この AWS CLI コマンドでは、
create-collection
CLI オペレーションの JSON 出力を表示します。collection-id
の値は、作成するコレクションの名前に置き換えます。aws rekognition create-collection \ --collection-id "
collectionname
" - Python
-
次の例では、コレクションを作成して、その Amazon リソースネーム (ARN) を表示します。
collection_id
の値は、作成するコレクションの名前に変更します。#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 create_collection(collection_id): client=boto3.client('rekognition') #Create a collection print('Creating collection:' + collection_id) response=client.create_collection(CollectionId=collection_id) print('Collection ARN: ' + response['CollectionArn']) print('Status code: ' + str(response['StatusCode'])) print('Done...') def main(): collection_id='Collection' create_collection(collection_id) if __name__ == "__main__": main()
- .NET
-
次の例では、コレクションを作成して、その Amazon リソースネーム (ARN) を表示します。
collectionId
の値は、作成するコレクションの名前に変更します。//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 CreateCollection { public static void Example() { AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); String collectionId = "MyCollection"; Console.WriteLine("Creating collection: " + collectionId); CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest() { CollectionId = collectionId }; CreateCollectionResponse createCollectionResponse = rekognitionClient.CreateCollection(createCollectionRequest); Console.WriteLine("CollectionArn : " + createCollectionResponse.CollectionArn); Console.WriteLine("Status code : " + createCollectionResponse.StatusCode); } }
- Node.JS
-
次の例では、の値を置き換えます。
region
アカウントに関連付けられているリージョンの名前で、の値を置き換えます。collectionName
コレクションの名前を指定します。import { CreateCollectionCommand} from "@aws-sdk/client-rekognition"; import { RekognitionClient } from "@aws-sdk/client-rekognition"; // Set the AWS Region. const REGION = "region"; //e.g. "us-east-1" const rekogClient = new RekognitionClient({ region: REGION }); // Name the collecction const collection_name = "collectionName" const createCollection = async (collectionName) => { try { console.log(`Creating collection: ${collectionName}`) const data = await rekogClient.send(new CreateCollectionCommand({CollectionId: collectionName})); console.log("Collection ARN:") console.log(data.CollectionARN) console.log("Status Code:") console.log(String(data.StatusCode)) console.log("Success.", data); return data; } catch (err) { console.log("Error", err.stack); } }; createCollection(collection_name)
CreateCollection オペレーションのリクエスト
CreationCollection
への入力は、作成するコレクションの名前です。
{ "CollectionId": "MyCollection" }
CreateCollection オペレーションのレスポンス
Amazon Rekognition はコレクションを作成し、新しく作成したコレクションの Amazon リソースネーム (ARN) を返します。
{ "CollectionArn": "aws:rekognition:us-east-1:acct-id:collection/examplecollection", "StatusCode": 200 }