Example #1
0
        public void Map(JToken container, List <Face> faces)
        {
            JToken categoriesNode = GetCategories(container);

            if (categoriesNode.HasValues)
            {
                foreach (JToken category in categoriesNode)
                {
                    JToken detail = category["detail"];

                    if (category["detail"] != null && category["detail"].Value <JToken>()["celebrities"] != null)
                    {
                        IEnumerable <JToken> celebritiesNode = category["detail"].Value <JToken>()["celebrities"].Value <JArray>();

                        foreach (JToken celebrity in celebritiesNode)
                        {
                            JToken faceRectangle = celebrity["faceRectangle"].Value <JToken>();
                            Box    celebirtyBox  = _boxMapper.Map(faceRectangle);

                            Face face = faces
                                        .Where(FaceFilter(celebirtyBox))
                                        .Select(f => f)
                                        .FirstOrDefault();

                            if (face != null)
                            {
                                face.CelebrityName  = celebrity["name"].Value <string>();
                                face.CelebrityScore = celebrity["confidence"].Value <decimal>();
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public List <Face> Map(JToken container)
        {
            List <Face> faces = new List <Face>();

            foreach (JToken face in container)
            {
                JToken faceRectangle  = face["faceRectangle"].Value <JToken>();
                JToken faceAttributes = face["faceAttributes"].Value <JToken>();

                Face currentFace = new Face
                {
                    Age       = faceAttributes["age"].Value <int>(),
                    Gender    = faceAttributes["gender"].Value <string>(),
                    Box       = _boxMapper.Map(faceRectangle),
                    Emotions  = _emotionMapper.Map(faceAttributes),
                    Landmarks = _landmarkMapper.Map(face)
                };

                faces.Add(currentFace);
            }

            return(faces);
        }