Structure containing attributes of the face that the algorithm detected.
예제 #1
0
        public ClsPrediction(ObjectType defaultObjType, Camera cam, Amazon.Rekognition.Model.FaceDetail AiDetectionObject, ClsImageQueueItem curImg, ClsURLItem curURL)
        {
            this._defaultObjType = defaultObjType;
            this._cam            = cam;
            this._cururl         = curURL;
            this._curimg         = curImg;
            this.Camera          = cam.Name;
            this.BICamName       = cam.BICamName;
            this.ImageHeight     = curImg.Height;
            this.ImageWidth      = curImg.Width;
            this.Server          = curURL.CurSrv;
            this.Time            = DateTime.Now;
            this.Filename        = curImg.image_path;

            if (AiDetectionObject == null || cam == null)
            {
                Log("Error: Prediction or Camera was null?", "", this._cam.Name);
                this.Result = ResultType.Error;
                return;
            }

            this.RectHeight = Convert.ToInt32(Math.Round(curImg.Height * AiDetectionObject.BoundingBox.Height));
            this.RectWidth  = Convert.ToInt32(Math.Round(curImg.Width * AiDetectionObject.BoundingBox.Width));

            double right = (curImg.Width * AiDetectionObject.BoundingBox.Left) + this.RectWidth;
            double left  = curImg.Width * AiDetectionObject.BoundingBox.Left;

            double top    = curImg.Height * AiDetectionObject.BoundingBox.Top;
            double bottom = (curImg.Height * AiDetectionObject.BoundingBox.Top) + this.RectHeight;

            this.XMin = Convert.ToInt32(Math.Round(left));
            this.YMin = Convert.ToInt32(Math.Round(top));

            this.XMax = Convert.ToInt32(Math.Round(right));
            this.YMax = Convert.ToInt32(Math.Round(bottom));

            //[{Global.UpperFirst(AiDetectionObject.Attributes.Gender)}, {AiDetectionObject.Attributes.Age}, {Global.UpperFirst(AiDetectionObject.Attributes.Emotion)}]
            string         emotions     = "";
            List <Emotion> emotionslist = new List <Emotion>();

            if (AiDetectionObject.Emotions != null && AiDetectionObject.Emotions.Count > 0)
            {
                foreach (Emotion em in AiDetectionObject.Emotions)
                {
                    if (em.Confidence >= 25)
                    {
                        emotionslist.Add(em);
                    }
                }
                if (emotionslist.Count > 0)
                {
                    //sort so highest conf is first
                    emotionslist = emotionslist.OrderByDescending(a => a.Confidence).ToList();
                    emotions     = ", ";
                    int cnt = 0;
                    foreach (Emotion em in emotionslist)
                    {
                        emotions += $"{Global.UpperFirst(em.Type.ToString().ToLower())};";
                        cnt++;
                        if (cnt > 3)
                        {
                            break;
                        }
                    }
                    emotions = emotions.Trim(" ;".ToCharArray());
                }
            }

            string gender = "";

            if (AiDetectionObject.Gender != null)
            {
                gender = $", {AiDetectionObject.Gender.Value}";
            }

            string age = "";

            if (AiDetectionObject.AgeRange != null)
            {
                age = $", {AiDetectionObject.AgeRange.Low}-{AiDetectionObject.AgeRange.High}";
            }

            string smile = "";

            if (AiDetectionObject.Smile.Value)
            {
                smile = ", Smile";
            }

            string eyeglasses = "";

            if (AiDetectionObject.Eyeglasses.Value)
            {
                eyeglasses = ", Eyeglasses";
            }

            string sunglasses = "";

            if (AiDetectionObject.Sunglasses.Value)
            {
                sunglasses = ", Sunglasses";
            }

            string beard = "";

            if (AiDetectionObject.Beard.Value)
            {
                beard = ", Beard";
            }

            string mustache = "";

            if (AiDetectionObject.Mustache.Value)
            {
                mustache = ", Mustache";
            }

            string mouthopen = "";

            if (AiDetectionObject.MouthOpen.Value)
            {
                mouthopen = ", MouthOpen";
            }


            this.Label = "Face";

            this.Detail = $"{gender}{age}{emotions}{smile}{eyeglasses}{sunglasses}{beard}{mustache}{mouthopen}".Trim(", ".ToCharArray());

            this.Confidence = AiDetectionObject.Confidence;

            this.GetObjectType();
        }