示例#1
0
        private async Task <int> ProcessLabels(ILambdaContext context, string jobId)
        {
            int success = 0; //success

            GetPersonTrackingResponse response = null;

            do
            {
                GetPersonTrackingRequest request = new GetPersonTrackingRequest
                {
                    JobId      = jobId,
                    MaxResults = MaxResults,
                    NextToken  = response?.NextToken,
                    SortBy     = PersonTrackingSortBy.TIMESTAMP
                };

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

                //more than one person detected
                if (response.Persons.Any(x => x.Person.Index != 0))
                {
                    success = 1;
                    break;
                }

                //video brightness is low
                if (response.Persons.Any(x => x.Person.Face?.Quality.Brightness < 50.0f))
                {
                    success = 2;
                    break;
                }

                //instructor is not clear in the video
                if (response.Persons.Any(x => x.Person.Face?.Confidence < 50))
                {
                    success = 3;
                    break;
                }

                //facial expressions are acceptable
                if (response.Persons.Any(x => x.Person.Face != null && x.Person.Face.Emotions.Any(y => invalidEmotions.Contains(y.Type))))
                {
                    success = 4;
                    break;
                }
            } while (response?.NextToken != null);

            return(success);
        }
示例#2
0
        //private readonly List<EmotionName> invalidEmotions = new List<EmotionName>
        //{
        //  EmotionName.SAD, EmotionName.SURPRISED, EmotionName.ANGRY, EmotionName.CONFUSED, EmotionName.DISGUSTED,
        //  EmotionName.UNKNOWN
        //};

        private async Task <bool> ProcessLabels(ILambdaContext context, string jobId)
        {
            bool success = true;

            GetPersonTrackingResponse response = null;

            do
            {
                GetPersonTrackingRequest request = new GetPersonTrackingRequest
                {
                    JobId      = jobId,
                    MaxResults = MaxResults,
                    NextToken  = response?.NextToken,
                    SortBy     = PersonTrackingSortBy.TIMESTAMP
                };

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

                //more than one person detected

                if (response.Persons.Any(x => x.Person.Index != 0))
                {
                    success = false;
                    break;
                }

                if (response.Persons.Any(x => x.Person.Face?.Quality.Brightness < 50.0f || x.Person.Face?.Quality.Sharpness < 50.0f))
                {
                    success = false;
                    break;
                }

                if (response.Persons.Any(x => x.Person.Face?.Confidence < 50))
                {
                    success = false;
                    break;
                }

                //if(response.Persons.Any(x => x.Person.Face?.Emotions.Any(y => invalidEmotions.Contains(y.Type))))
            } while (response?.NextToken != null);

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

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

            while (context.ReadAtDepth(targetDepth))
            {
                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("Persons", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <PersonDetection, PersonDetectionUnmarshaller>(PersonDetectionUnmarshaller.Instance);
                    response.Persons = 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);
        }