Exemple #1
0
        /// <summary>
        /// Get the world position of a local space normalized point of a Quad
        /// </summary>
        /// <param name="fp"></param>
        /// <returns></returns>
        Vector3 GetWorldPoint(FeaturePoint fp)
        {
            Vector3 fpLocal = NormalizePoint(fp);


            return(transform.TransformPoint(fpLocal));
        }
Exemple #2
0
        /// <summary>
        /// Get a normalized position based on the input texture
        /// </summary>
        /// <param name="fp">Feature point to normalize</param>
        /// <returns>A normalized local point with XY coordinates</returns>
        Vector3 NormalizePoint(FeaturePoint fp)
        {
            if (DebugTexture == null)
            {
                return(Vector3.zero);
            }

            return(new Vector3(fp.x / (float)DebugTexture.width - 0.5f, (1 - fp.y / (float)DebugTexture.height) - 0.5f, 0));
        }
 Affdex.FeaturePoint maxPoint(Affdex.FeaturePoint[] points)
 {
     Affdex.FeaturePoint ret = points[0];
     foreach (Affdex.FeaturePoint point in points)
     {
         if (point.X > ret.X)
         {
             ret.X = point.X;
         }
         if (point.Y > ret.Y)
         {
             ret.Y = point.Y;
         }
     }
     return(ret);
 }
        private void DrawResults(Graphics g, Dictionary <int, Affdex.Face> faces)
        {
            Pen   whitePen    = new Pen(Color.OrangeRed);
            Pen   redPen      = new Pen(Color.DarkRed);
            Pen   bluePen     = new Pen(Color.DarkBlue);
            Font  aFont       = new Font(FontFamily.GenericSerif, 8, FontStyle.Bold);
            float radius      = 2;
            int   spacing     = 10;
            int   left_margin = 30;

            foreach (KeyValuePair <int, Affdex.Face> pair in faces)
            {
                Affdex.Face face = pair.Value;
                foreach (Affdex.FeaturePoint fp in face.FeaturePoints)
                {
                    g.DrawCircle(whitePen, fp.X, fp.Y, radius);
                }

                Affdex.FeaturePoint tl = minPoint(face.FeaturePoints);
                Affdex.FeaturePoint br = maxPoint(face.FeaturePoints);

                int padding = (int)tl.Y;

                g.DrawString(String.Format("ID: {0}", pair.Key), aFont, whitePen.Brush, new PointF(br.X, padding += spacing));
                g.DrawString("APPEARANCE", aFont, bluePen.Brush, new PointF(br.X, padding += (spacing * 2)));
                g.DrawString(face.Appearance.Gender.ToString(), aFont, whitePen.Brush, new PointF(br.X, padding                += spacing));
                g.DrawString(face.Appearance.Age.ToString(), aFont, whitePen.Brush, new PointF(br.X, padding                   += spacing));
                g.DrawString(face.Appearance.Ethnicity.ToString(), aFont, whitePen.Brush, new PointF(br.X, padding             += spacing));
                g.DrawString("Glasses: " + face.Appearance.Glasses.ToString(), aFont, whitePen.Brush, new PointF(br.X, padding += spacing));

                g.DrawString("EMOJIs", aFont, bluePen.Brush, new PointF(br.X, padding += (spacing * 2)));
                g.DrawString("DominantEmoji: " + face.Emojis.dominantEmoji.ToString(), aFont,
                             (face.Emojis.dominantEmoji != Affdex.Emoji.Unknown) ? whitePen.Brush : redPen.Brush,
                             new PointF(br.X, padding += spacing));

                foreach (String emojiName in Enum.GetNames(typeof(Affdex.Emoji)))
                {
                    PropertyInfo prop = face.Emojis.GetType().GetProperty(emojiName.ToLower());
                    if (prop != null)
                    {
                        float  value = (float)prop.GetValue(face.Emojis, null);
                        string c     = String.Format("{0}: {1:0.00}", emojiName, value);
                        g.DrawString(c, aFont, (value > 50) ? whitePen.Brush : redPen.Brush, new PointF(br.X, padding += spacing));
                    }
                }

                g.DrawString("EXPRESSIONS", aFont, bluePen.Brush, new PointF(br.X, padding += (spacing * 2)));
                foreach (PropertyInfo prop in typeof(Affdex.Expressions).GetProperties())
                {
                    float  value = (float)prop.GetValue(face.Expressions, null);
                    String c     = String.Format("{0}: {1:0.00}", prop.Name, value);
                    g.DrawString(c, aFont, (value > 50) ? whitePen.Brush : redPen.Brush, new PointF(br.X, padding += spacing));
                }

                g.DrawString("EMOTIONS", aFont, bluePen.Brush, new PointF(br.X, padding += (spacing * 2)));

                foreach (PropertyInfo prop in typeof(Affdex.Emotions).GetProperties())
                {
                    float  value = (float)prop.GetValue(face.Emotions, null);
                    String c     = String.Format("{0}: {1:0.00}", prop.Name, value);
                    g.DrawString(c, aFont, (value > 50) ? whitePen.Brush : redPen.Brush, new PointF(br.X, padding += spacing));
                }
            }
        }