/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetFaceDetectionResponse response = new GetFaceDetectionResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Faces", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <FaceDetection, FaceDetectionUnmarshaller>(FaceDetectionUnmarshaller.Instance);
                    response.Faces = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("JobStatus", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.JobStatus = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("StatusMessage", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.StatusMessage = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("VideoMetadata", targetDepth))
                {
                    var unmarshaller = VideoMetadataUnmarshaller.Instance;
                    response.VideoMetadata = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Esempio n. 2
0
        private async Task <bool> ProcessLabels(ILambdaContext context, string jobId)
        {
            GetFaceDetectionResponse response = null;

            do
            {
                GetFaceDetectionRequest request = new GetFaceDetectionRequest()
                {
                    JobId      = jobId,
                    MaxResults = MaxResults,
                    NextToken  = response?.NextToken,
                };

                response = await this.rekClient.GetFaceDetectionAsync(request).ConfigureAwait(false);

                if (response.Faces.Count != 1 || !(response.Faces[0].Face.Confidence > 60))
                {
                    return(false);
                }

                FaceDetail face = response.Faces[0].Face;

                if (face.Emotions.Any(x => this.invalidEmotions.Any(y => y == x.Type)))
                {
                    return(false);
                }

                if (!face.EyesOpen.Value || face.EyesOpen.Confidence < 60)
                {
                    return(false);
                }

                if (face.Quality.Brightness < 50.00f || face.Quality.Sharpness < 50.00f)
                {
                    return(false);
                }

                return(true);
            } while (response?.NextToken != null);
        }