public async Task ExecuteAsync() { var credentials = new BasicAWSCredentials(this.options.AccessKey, this.options.SecretKey); var clientConfig = new AmazonRekognitionConfig { RegionEndpoint = this.options.Region, AllowAutoRedirect = true, DisableLogging = true, MaxConnectionsPerServer = null, LogMetrics = false, LogResponse = false, UseDualstackEndpoint = false, }; clientConfig.Validate(); using var client = new AmazonRekognitionClient(credentials, clientConfig); try { await client.DescribeCollectionAsync( new DescribeCollectionRequest { CollectionId = this.options.CollectionID }).ConfigureAwait(false); } catch (ResourceNotFoundException) { await client.CreateCollectionAsync( new CreateCollectionRequest { CollectionId = this.options.CollectionID }).ConfigureAwait(false); } var files = this.options.Directory.EnumerateFiles(this.options.Pattern, enumerationOptions); // Output CSV data: Console.WriteLine("FileName,FaceID"); foreach (FileInfo file in files) { using var stream = new DecoyMemoryStream(file.OpenRead(), leaveOpen: false); var result = await client.IndexFacesAsync(new IndexFacesRequest { CollectionId = this.options.CollectionID, DetectionAttributes = detectionAttributes, MaxFaces = 1, QualityFilter = QualityFilter.AUTO, Image = new Image { Bytes = stream } }).ConfigureAwait(false); if (result.FaceRecords != null && result.FaceRecords.Count > 0) { Console.WriteLine("{0},{1}", file.Name, result.FaceRecords[0].Face.FaceId); } else { Console.WriteLine("{0},{1}", file.Name, "NotDetected"); } } }
// snippet-start:[Rekognition.dotnetv3.DescribeCollectionExample] public static async Task Main() { var rekognitionClient = new AmazonRekognitionClient(); string collectionId = "MyCollection"; Console.WriteLine($"Describing collection: {collectionId}"); var describeCollectionRequest = new DescribeCollectionRequest() { CollectionId = collectionId, }; var describeCollectionResponse = await rekognitionClient.DescribeCollectionAsync(describeCollectionRequest); Console.WriteLine($"Collection ARN: {describeCollectionResponse.CollectionARN}"); Console.WriteLine($"Face count: {describeCollectionResponse.FaceCount}"); Console.WriteLine($"Face model version: {describeCollectionResponse.FaceModelVersion}"); Console.WriteLine($"Created: {describeCollectionResponse.CreationTimestamp}"); }