コード例 #1
0
        public static void FaceAddition(string collectionId, string bucket, string faceToBeAdded)
        {
            AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(RegionEndpoint.APSouth1);

            Image image = new Image()
            {
                S3Object = new S3Object()
                {
                    Bucket = bucket,
                    Name   = faceToBeAdded
                }
            };

            IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
            {
                Image               = image,
                CollectionId        = collectionId,
                ExternalImageId     = faceToBeAdded,
                DetectionAttributes = new List <String>()
                {
                    "ALL"
                }
            };

            var indexFacesResponse = rekognitionClient.IndexFacesAsync(indexFacesRequest);

            Console.WriteLine(faceToBeAdded + " added");
            foreach (FaceRecord faceRecord in indexFacesResponse.Result.FaceRecords)
            {
                Console.WriteLine("Face detected: Faceid is " +
                                  faceRecord.Face.FaceId);
            }
        }
コード例 #2
0
        private static void IndexPhoto(string photo)
        {
            Console.WriteLine("Attempting to index S3 photo file " + photo);

            Image image = new Image()
            {
                S3Object = new S3Object()
                {
                    Bucket = bucket,
                    Name   = photo
                }
            };

            IndexFacesRequest request = new IndexFacesRequest()
            {
                Image               = image,
                CollectionId        = collectionId,
                ExternalImageId     = photo,
                DetectionAttributes = new List <String>()
                {
                    "ALL"
                }
            };

            IndexFacesResponse response = rekognitionClient.IndexFacesAsync(request).Result;

            Console.WriteLine(photo + " added");

            foreach (FaceRecord faceRecord in response.FaceRecords)
            {
                Console.WriteLine("Face detected: Faceid is " +
                                  faceRecord.Face.FaceId);
            }
        }
コード例 #3
0
    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");
            }
        }
    }
コード例 #4
0
        /// <summary>
        /// This function add images to the dyFace Collection
        /// Function Name: "dyFaceRekognitionAddToCollection"
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <List <string> > AddToCollection(string input, ILambdaContext context)
        {
            AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();

            String        collectionId  = "dyFaceCollection";
            List <string> collectionIds = await GetCollections(rekognitionClient);

            List <string> reasons = new List <string>();

            //error handling
            if (!collectionIds.Contains(collectionId))
            {
                int createCollectionResponse = await CreateCollection(rekognitionClient, collectionId);

                if (createCollectionResponse < 200 || createCollectionResponse > 299)
                {
                    reasons.Add("Failure Creating Collection = " + createCollectionResponse);
                    return(reasons);
                }
            }

            IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
            {
                Image =
                {
                    S3Object   = new S3Object()
                    {
                        Bucket = "dyface-test-bucket",
                        Name   = input
                    }
                },
                CollectionId        = collectionId,
                ExternalImageId     = input,
                DetectionAttributes = new List <String>()
                {
                    "ALL"
                }
            };

            IndexFacesResponse indexFacesResponse = await rekognitionClient.IndexFacesAsync(indexFacesRequest);

            foreach (UnindexedFace unindexedFace in indexFacesResponse.UnindexedFaces)
            {
                reasons.Add(unindexedFace.Reasons.ToString());
            }

            return(reasons);
        }
コード例 #5
0
        public async void Addface()
        {
            String collectionId = "faceCollection";
            String bucket       = "face-identify";
            String photo        = "BrotherP.jpg";

            string accessKey = "AKIAST4HFDODRNXMOAPJ";
            string secretKey = "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";

            AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(accessKey, secretKey, Amazon.RegionEndpoint.APSoutheast1);

            Image image = new Image()
            {
                S3Object = new S3Object()
                {
                    Bucket = bucket,
                    Name   = photo
                }
            };

            IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
            {
                Image               = image,
                CollectionId        = collectionId,
                ExternalImageId     = photo,
                DetectionAttributes = new List <String>()
                {
                    "ALL"
                }
            };

            IndexFacesResponse indexFacesResponse = await rekognitionClient.IndexFacesAsync(indexFacesRequest);

            Console.WriteLine(photo + " added");
            foreach (FaceRecord faceRecord in indexFacesResponse.FaceRecords)
            {
                Console.WriteLine("Face detected: Faceid is " +
                                  faceRecord.Face.FaceId);
            }
        }
コード例 #6
0
        public static void Example()
        {
            String collectionId = "BhavCollection";
            String bucket       = "bhavesh-aws-bucket";
            String photo        = "Malik.jpg";

            AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(RegionEndpoint.APSouth1);

            Image image = new Image()
            {
                S3Object = new S3Object()
                {
                    Bucket = bucket,
                    Name   = photo
                }
            };

            IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
            {
                Image               = image,
                CollectionId        = collectionId,
                ExternalImageId     = photo,
                DetectionAttributes = new List <String>()
                {
                    "ALL"
                }
            };

            var indexFacesResponse = rekognitionClient.IndexFacesAsync(indexFacesRequest);

            Console.WriteLine(photo + " added");
            foreach (FaceRecord faceRecord in indexFacesResponse.Result.FaceRecords)
            {
                Console.WriteLine("Face detected: Faceid is " +
                                  faceRecord.Face.FaceId);
            }
        }
コード例 #7
0
        // snippet-start:[Rekognition.dotnetv3.AddFacesExample]
        public static async Task Main()
        {
            string collectionId = "MyCollection2";
            string bucket       = "doc-example-bucket";
            string photo        = "input.jpg";

            var rekognitionClient = new AmazonRekognitionClient();

            var image = new Image
            {
                S3Object = new S3Object
                {
                    Bucket = bucket,
                    Name   = photo,
                },
            };

            var indexFacesRequest = new IndexFacesRequest
            {
                Image               = image,
                CollectionId        = collectionId,
                ExternalImageId     = photo,
                DetectionAttributes = new List <string>()
                {
                    "ALL"
                },
            };

            IndexFacesResponse indexFacesResponse = await rekognitionClient.IndexFacesAsync(indexFacesRequest);

            Console.WriteLine($"{photo} added");
            foreach (FaceRecord faceRecord in indexFacesResponse.FaceRecords)
            {
                Console.WriteLine($"Face detected: Faceid is {faceRecord.Face.FaceId}");
            }
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task FunctionHandler(S3Event input, ILambdaContext context)
        {
            // Initialize the Amazon Cognito credentials provider
            CognitoAWSCredentials credentials = new CognitoAWSCredentials(
                "us-east-1:6d711ae9-1084-4a71-9ef6-7551ca74ad0b", // Identity pool ID
                RegionEndpoint.USEast1                            // Region
                );

            dynamoDbClient = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
            Table customersTbl = Table.LoadTable(dynamoDbClient, "Customer");


            AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();
            IAmazonS3 s3Client = new AmazonS3Client(RegionEndpoint.USEast2);

            //Debug.WriteLine("Creating collection: " + FACE_COLLECTION_ID);
            //CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest()
            //{
            //    CollectionId = FACE_COLLECTION_ID
            //};

            //CreateCollectionResponse createCollectionResponse = rekognitionClient.CreateCollectionAsync(createCollectionRequest).Result;
            //Debug.WriteLine("CollectionArn : " + createCollectionResponse.CollectionArn);
            //Debug.WriteLine("Status code : " + createCollectionResponse.StatusCode);


            foreach (var record in input.Records)
            {
                //if(!SupportedImageTypes.Contains(Path.GetExtension(record.S3.Object.Key)))
                //{
                //    Debug.WriteLine($"Object {record.S3.Bucket.Name}:{record.S3.Object.Key} is not a supported image type");
                //    continue;
                //}

                Image image = new Image()
                {
                    S3Object = new Amazon.Rekognition.Model.S3Object
                    {
                        Bucket = record.S3.Bucket.Name,
                        Name   = record.S3.Object.Key
                    }
                };

                GetObjectTaggingResponse taggingResponse = s3Client.GetObjectTaggingAsync(
                    new GetObjectTaggingRequest
                {
                    BucketName = record.S3.Bucket.Name,
                    Key        = record.S3.Object.Key
                }
                    ).Result;

                Tag customerID = taggingResponse.Tagging[0];//TODO: HARDCODING!!


                IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
                {
                    Image               = image,
                    CollectionId        = FACE_COLLECTION_ID,
                    ExternalImageId     = record.S3.Object.Key,
                    DetectionAttributes = new List <String>()
                    {
                        "ALL"
                    }
                };

                IndexFacesResponse indexFacesResponse = rekognitionClient.IndexFacesAsync(indexFacesRequest).Result;

                Debug.WriteLine(record.S3.Object.Key + " added");
                foreach (FaceRecord faceRecord in indexFacesResponse.FaceRecords)
                {
                    Debug.WriteLine("Face detected: Faceid is " + faceRecord.Face.FaceId);

                    Console.WriteLine("\nAfter Indexing, Updating FaceID of the Customer....");
                    string partitionKey = customerID.Value;

                    var customer = new Document();
                    customer["Id"] = Int32.Parse(partitionKey);
                    // List of attribute updates.
                    // The following replaces the existing authors list.
                    customer["FaceId"] = faceRecord.Face.FaceId;

                    // Optional parameters.
                    UpdateItemOperationConfig config = new UpdateItemOperationConfig
                    {
                        // Get updated item in response.
                        ReturnValues = ReturnValues.AllNewAttributes
                    };
                    Document updatedCustomer = customersTbl.UpdateItemAsync(customer, config).Result;
                    Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ...");
                    PrintDocument(updatedCustomer);
                }
            }
            return;
        }