public DetectFacesResponse DetectFaces(DetectFaceParams dfp) { DetectFacesResponse resp = null; var conf = new AmazonRekognitionConfig() { RegionEndpoint = dfp.RegEndpoint }; using (recClient = new AmazonRekognitionClient(awsAccessKeyId, awsSecretAccessKey, conf)) { DetectFacesRequest detectFacesRequest = new DetectFacesRequest() { Image = new Image() { S3Object = new S3Object() { Name = dfp.PhotoName, Bucket = dfp.BucketName }, }, // Attributes can be "ALL" or "DEFAULT". // "DEFAULT": BoundingBox, Confidence, Landmarks, Pose, and Quality. // "ALL": See https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Rekognition/TFaceDetail.html Attributes = new List <String>() { "ALL" } }; try { resp = recClient.DetectFaces(detectFacesRequest); if (resp == null) { throw new Exception("AmazonRekognitionClient DetectFaces method call return null."); } //bool hasAll = detectFacesRequest.Attributes.Contains("ALL"); //foreach (FaceDetail face in resp.Result.FaceDetails) //{ // Console.WriteLine("BoundingBox: top={0} left={1} width={2} height={3}", face.BoundingBox.Left, // face.BoundingBox.Top, face.BoundingBox.Width, face.BoundingBox.Height); // Console.WriteLine("Confidence: {0}\nLandmarks: {1}\nPose: pitch={2} roll={3} yaw={4}\nQuality: {5}", // face.Confidence, face.Landmarks.Count, face.Pose.Pitch, // face.Pose.Roll, face.Pose.Yaw, face.Quality); // if (hasAll) // Console.WriteLine("The detected face is estimated to be between " + // face.AgeRange.Low + " and " + face.AgeRange.High + " years old."); //} } catch (Exception e) { Console.WriteLine(e.Message); } } return(resp); }
public DetectFacesResponse Recognise(RecogniseParams recParam) { //1. PutObjectIntoS3 if (String.IsNullOrEmpty(recParam.PhotoName)) { throw new Exception("AmazonRekognition Recognise method: photoName parameter must have value."); } var photoName = $"{recParam.PhotoName}_{DateTime.Now}"; var pop = new PutObjectParams() { PhotoName = photoName, PhotoVersion = recParam.PhotoVersion, BucketName = recParam.BucketName, RegEndpoint = recParam.RegEndpoint, InputStrem = recParam.InputStream, ContentType = recParam.ContentType }; var resp = PutObjectIntoS3(pop); if (resp == null) { throw new Exception($"PutObjectIntoS3 response is null in Recognise method PhotoName: {photoName}"); } //2. DetectFaces var dfp = new DetectFaceParams() { PhotoName = photoName, PhotoVersion = recParam.PhotoVersion, BucketName = recParam.BucketName, RegEndpoint = recParam.RegEndpoint }; var detectFaceResp = DetectFaces(dfp); if (detectFaceResp == null) { throw new Exception($"DetectFaces response is null in Recognise method PhotoName: {photoName}"); } return(detectFaceResp); }
public void DetectFacesTest() { //Arrange var param = new DetectFaceParams() { BucketName = "nvirginiadekanybucket", PhotoName = "steve", PhotoVersion = String.Empty }; AmazonRekognition service = new AmazonRekognition(awsAccessKeyId, awsSecretAccessKey); //Act var resp = service.DetectFaces(param); bool hasItem = resp.FaceDetails.Any(); //Assert Assert.AreEqual(true, hasItem); }