Ejemplo n.º 1
0
        private double dist(Affdex.FeaturePoint fp1, Affdex.FeaturePoint fp2)
        {
            double res = 0;

            double dfX = fp1.X - fp2.X;
            double dfY = fp1.Y - fp2.Y;

            res = Math.Sqrt(dfX * dfX + dfY * dfY);

            return(res);
        }
 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   redPen      = new Pen(Color.Red);
            Pen   bluePen     = new Pen(Color.DarkBlue);
            Font  aFont       = new Font(FontFamily.GenericSerif, 20, FontStyle.Bold);
            float radius      = 2;
            int   spacing     = 30;
            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);

                //// Trim results to be within screen
                //br.X = System.Math.Min( br.X , System.Math.Max(this.Size.Width  - 220, 0) );
                //br.Y = System.Math.Min( br.Y , System.Math.Max(this.Size.Height - 800, 0) );
                //
                //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));
                //}
            }
            this.comm_results();
        }
Ejemplo n.º 4
0
 public FeaturePointEntity(Guid guid, int id, Affdex.FeaturePoint point)
 {
     this.point = point;
     FaceGuid = guid;
 }
Ejemplo n.º 5
0
 public FeaturePointEntity(Guid guid, int id, Affdex.FeaturePoint point)
 {
     this.point = point;
     FaceGuid   = guid;
 }
Ejemplo n.º 6
0
        private void DrawResults(Graphics g, Dictionary <int, Affdex.Face> faces)
        {
            Pen   whitePen    = new Pen(Color.White, 2);
            Pen   blackPen    = new Pen(Color.Black, 2f);
            Brush whiteBrush  = new SolidBrush(Color.White);
            Font  aFont       = new Font(FontFamily.GenericSerif, 15, FontStyle.Bold);
            float radius      = 3;
            int   spacing     = 10;
            int   left_margin = 30;

            if (this.start)
            {
                if (faces.Values.Count < 1)
                {
                    this.vogBlink.reset();

                    data[0] = blinkVOG.NONE;
                    data[1] = -1;
                    data[2] = frameNo;

                    if (this.outlet.have_consumers())
                    {
                        outlet.push_sample(data);
                    }
                }
                else
                {
                    foreach (KeyValuePair <int, Affdex.Face> pair in faces)
                    {
                        Affdex.Face face = pair.Value;

                        int i = 0;

                        foreach (Affdex.FeaturePoint fp in face.FeaturePoints)
                        {
                            if (i == EYE_LEFT_OUTER)
                            {
                                eyeLeft[0] = fp;
                            }
                            else if (i == EYE_LEFT_INNER)
                            {
                                eyeLeft[1] = fp;
                            }
                            else if (i == EYE_RIGHT_OUTER)
                            {
                                eyeRight[0] = fp;
                            }
                            else if (i == EYE_RIGHT_INNER)
                            {
                                eyeRight[1] = fp;
                            }

                            if (i == EYE_LEFT_UP)
                            {
                                eyeLeft[2] = fp;
                            }
                            else if (i == EYE_LEFT_BOTTOM)
                            {
                                eyeLeft[3] = fp;
                            }
                            else if (i == EYE_RIGHT_UP)
                            {
                                eyeRight[2] = fp;
                            }
                            else if (i == EYE_RIGHT_BOTTOM)
                            {
                                eyeRight[3] = fp;
                            }

                            g.DrawCircle(whitePen, fp.X, fp.Y, radius);
                            i++;
                        }

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

                        double leftW  = dist(eyeLeft[0], eyeLeft[1]);
                        double rightW = dist(eyeRight[0], eyeRight[1]);
                        double leftH  = dist(eyeLeft[2], eyeLeft[3]);
                        double rightH = dist(eyeRight[2], eyeRight[3]);

                        ear = ((leftH + rightH) / 2) / ((leftW + rightW) / 2);

                        data[0] = 0;
                        data[1] = ear;
                        data[2] = frameNo;
                        //data[3] = eyeLeft[0]; data[4] = eyeLeft[1]; data[5] = eyeLeft[2]; data[6] = eyeLeft[3];
                        //data[7] = eyeRight[0]; data[8] = eyeRight[1]; data[9] = eyeRight[2]; data[10] = eyeRight[3];


                        int padding = (int)(tl.Y * .75D);

                        int[] evento = this.vogBlink.apply(new double[] { ear });

                        data[0] = evento[0];

                        if (data[0] == blinkVOG.MLINK)
                        {
                            mlinkNo++;

                            if (this.cmdMultiBlink != null)
                            {
                                this.cmdMultiBlink.execute();
                            }
                        }
                        else if (data[0] == blinkVOG.WLINK)
                        {
                            WlinkNo++;
                            if (this.cmdWlink != null)
                            {
                                this.cmdWlink.execute();
                            }
                        }

                        data[0] *= 100;

                        /*
                         * if (ear < thres)
                         * {
                         *  blink = 1F;
                         *  initBlink = true;
                         * }
                         *
                         * if (initBlink && ear >= thres)
                         * {
                         *  blink = 0F;
                         *  initBlink = false;
                         *  blinkNo++;
                         *
                         *  data[0] = 1.0D;
                         * }
                         */

                        if (this.outlet.have_consumers())
                        {
                            outlet.push_sample(data);
                        }

                        /*
                         * String c = String.Format("{0}: {1}", "No. of Blink", blinkNo);
                         * g.DrawString(c, aFont, redPen.Brush, new PointF(br.X, padding += spacing));
                         */

                        String       c        = String.Format("{0}: {1}", "No. Multi-Blink", mlinkNo);
                        GraphicsPath p        = new GraphicsPath();
                        int          fontSize = 25;

                        p.AddString(
                            c,                           // text to draw
                            FontFamily.GenericSansSerif, // or any other font family
                            (int)FontStyle.Bold,         // font style (bold, italic, etc.)
                            g.DpiY * fontSize / 72,      // em size
                            new Point(10, 60),           // location where to draw text
                            new StringFormat());         // set options here (e.g. center alignment)
                        g.FillPath(whiteBrush, p);
                        g.DrawPath(blackPen, p);
                        p.Reset();
                        //g.DrawString(c, aFont, blackPen.Brush, new PointF( 10, 60 ));
                        //g.DrawString(c, aFont, whitePen.Brush, new PointF( 10, 60 ));

                        c = String.Format("{0}: {1}", "No. Wlink", WlinkNo);
                        p.AddString(
                            c,                           // text to draw
                            FontFamily.GenericSansSerif, // or any other font family
                            (int)FontStyle.Bold,         // font style (bold, italic, etc.)
                            g.DpiY * fontSize / 72,      // em size
                            new Point(10, 100),          // location where to draw text
                            new StringFormat());         // set options here (e.g. center alignment)
                        g.FillPath(whiteBrush, p);
                        g.DrawPath(blackPen, p);
                        p.Reset();
                        //g.DrawString(c, aFont, blackPen.Brush, new PointF( 10, 80 ));
                        //g.DrawString(c, aFont, whitePen.Brush, new PointF( 10, 80 ));

                        c = String.Format("{0}: {1:0.000}", "Time:", this.timeFromLastEvent.ElapsedMilliseconds / 1000F);
                        if (data[0] == blinkVOG.MLINK * 100 || data[0] == blinkVOG.WLINK * 100)
                        {
                            timeFromLastEvent = Stopwatch.StartNew();
                        }
                        p.AddString(
                            c,                           // text to draw
                            FontFamily.GenericSansSerif, // or any other font family
                            (int)FontStyle.Bold,         // font style (bold, italic, etc.)
                            g.DpiY * fontSize / 72,      // em size
                            new Point(10, 140),          // location where to draw text
                            new StringFormat());         // set options here (e.g. center alignment)
                        g.FillPath(whiteBrush, p);
                        g.DrawPath(blackPen, p);
                        p.Reset();

                        //g.DrawString(c, aFont, blackPen.Brush, new PointF( 10, 100 ));
                        //g.DrawString(c, aFont, whitePen.Brush, new PointF( 10, 100 ));

                        if (outputFile != null)
                        {
                            outputFile.Write(blink + "\t" + ear + "\t" + frameNo + "\n");
                        }
                    }
                }
            }
        }