public override void onImageResults(Dictionary <int, Affdex.Face> faces) { if (faces.Count > 0) { faceFound = true; foreach (KeyValuePair <int, Affdex.Face> pair in faces) { int FaceId = pair.Key; // The Face Unique Id. Affdex.Face face = pair.Value; // Instance of the face class containing emotions, and facial expression values. //Retrieve the Emotions Scores face.Expressions.TryGetValue(Expressions.BrowRaise, out raise); face.Expressions.TryGetValue(Expressions.BrowFurrow, out furrow); face.Expressions.TryGetValue(Expressions.LipSuck, out suck); face.Expressions.TryGetValue(Expressions.LipPucker, out pucker); //Retrieve the Interocular distance, the distance between two outer eye corners. //currentInterocularDistance = face.Measurements.interOcularDistance; //Retrieve the coordinates of the facial landmarks (face feature points) //featurePointsList = face.FeaturePoints; } } else { faceFound = false; } }
/// <summary> /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element. /// </summary> /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param> protected override void OnRender(System.Windows.Media.DrawingContext dc) { //For each face foreach (KeyValuePair <int, Affdex.Face> pair in Faces) { Affdex.Face face = pair.Value; FeaturePoint[] featurePoints = face.FeaturePoints; //Calculate bounding box corners coordinates. System.Windows.Point tl = new System.Windows.Point(featurePoints.Min(r => r.X) * XScale, featurePoints.Min(r => r.Y) * YScale); System.Windows.Point br = new System.Windows.Point(featurePoints.Max(r => r.X) * XScale, featurePoints.Max(r => r.Y) * YScale); System.Windows.Point bl = new System.Windows.Point(tl.X, br.Y); if (ShowPoints) { DrawPoints(featurePoints, dc, tl, br); } if (ShowMetrics) { DrawMetrics(face, dc, tl, br); } if (ShowEmojis) { DrawEmojis(face, dc, tl, br); } if (ShowAppearance) { DrawAppearance(face, dc, tl, br); } } base.OnRender(dc); }
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)); } } }
/// <summary> /// Set the face to show in editor. /// </summary> /// <param name="face">Face to show features of</param> public void ShowFace(Face face) { this.face = face; }
void ImageListener.onImageResults(Dictionary <int, Face> faces, Frame frame) { if (faces != null) { foreach (KeyValuePair <int, Affdex.Face> pair in faces) { Affdex.Face face = pair.Value; StringBuilder output = new StringBuilder(); faceStates.AddFace(face, frame.getTimestamp()); if (isFirstFrame) { faceStates.SetFrameData(frame.getHeight(), frame.getWidth()); output.Append(string.Format("{0,5}{1,9}", "Frame", "TimeScale")); foreach (PropertyInfo prop in typeof(Affdex.Expressions).GetProperties()) { output.Append(string.Format("#{0,19}", prop.Name)); } output.Append(Environment.NewLine); WriteInfoExpressions(output.ToString()); output.Clear(); output.Append(string.Format("{0,5}{1,9}", "Frame", "TimeScale")); foreach (PropertyInfo prop in typeof(Affdex.Emotions).GetProperties()) { output.Append(string.Format("#{0,19}", prop.Name)); } output.Append(Environment.NewLine); WriteInfoEmotions(output.ToString()); output.Clear(); output.Append("Face feature points" + Environment.NewLine); WriteInfoFeaturePoints(output.ToString()); output.Clear(); } isFirstFrame = false; //timescale and frame count output output.Append(string.Format("{0,4}#{1,9:0.0000}", frameProcessedCounter, frame.getTimestamp())); //expressions output foreach (PropertyInfo prop in typeof(Affdex.Expressions).GetProperties()) { float value = (float)prop.GetValue(face.Expressions, null); output.Append(string.Format("#{0,19:0.0000000}", value)); } output.Append(Environment.NewLine); WriteInfoExpressions(output.ToString()); //output of feature points output.Clear(); var featurePoints = face.FeaturePoints; foreach (var p in featurePoints) { output.Append(string.Format("{0:0}:{1:0};", p.X, p.Y)); } output.Append(Environment.NewLine); WriteInfoFeaturePoints(output.ToString()); output.Clear(); //timescale and frame count output output.Append(string.Format("{0,4}#{1,9:0.0000}", frameProcessedCounter, frame.getTimestamp())); //expressions output foreach (PropertyInfo prop in typeof(Affdex.Emotions).GetProperties()) { float value = (float)prop.GetValue(face.Emotions, null); output.Append(string.Format("#{0,19:0.0000000}", value)); } output.Append(Environment.NewLine); WriteInfoEmotions(output.ToString()); //TO DO: make handler for appearances frameProcessedCounter++; } } }
public void onImageResults(Dictionary <int, Affdex.Face> faces, Affdex.Frame frame) { //if (ready) { System.Console.WriteLine("faces count"); System.Console.WriteLine(faces.Count); //inputfile = detector.getName(); foreach (KeyValuePair <int, Affdex.Face> pair in faces) { Affdex.Face face = pair.Value; //adding values to the arraylist f.Add(face.Emotions.Fear); a.Add(face.Emotions.Anger); h.Add(face.Emotions.Joy); d.Add(face.Emotions.Disgust); sa.Add(face.Emotions.Sadness); su.Add(face.Emotions.Surprise); float[] emo = new float[6]; emo[0] = face.Emotions.Fear; emo[1] = face.Emotions.Anger; emo[2] = face.Emotions.Surprise; emo[3] = face.Emotions.Joy; emo[4] = face.Emotions.Sadness; emo[5] = face.Emotions.Disgust; progressBar1.Value = (int)face.Emotions.Anger; progressBar2.Value = (int)face.Emotions.Fear; progressBar4.Value = (int)face.Emotions.Surprise; progressBar5.Value = (int)face.Emotions.Joy; progressBar6.Value = (int)face.Emotions.Sadness; progressBar7.Value = (int)face.Emotions.Disgust; float engagement = face.Emotions.Engagement; float dominantEmotion = emo.Max(); int index = emo.ToList().IndexOf(dominantEmotion); if ((index == 0) && (emo[index] > 10)) { filepath = @"C:\Users\Rana\Desktop\data\Fear\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\fear.png"); label3.Text = "Afraid"; } else { if ((index == 1) && (emo[index] > 10)) { filepath = @"C:\Users\Rana\Desktop\data\Anger\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\angry.png"); label3.Text = "Angry"; } else { if ((index == 2) && (emo[index] > 10)) { System.Console.WriteLine(inputfile.Substring(28, 4)); filepath = @"C:\Users\Rana\Desktop\data\Surprise\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\surprise.png"); label3.Text = "Surprised"; } else { if ((index == 3) && (emo[index] > 10)) { filepath = @"C:\Users\Rana\Desktop\data\Joy\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\happy.png"); label3.Text = "Happy"; } else { if ((index == 4) && (emo[index] > 10)) { filepath = @"C:\Users\Rana\Desktop\data\Sadness\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\sad.png"); label3.Text = "Sad"; } else { if ((index == 5) && (emo[index] > 10)) { filepath = @"C:\Users\Rana\Desktop\data\Disgust\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\disgust.png"); label3.Text = "Disgusted"; } else { System.Console.WriteLine(inputfile); filepath = @"C:\Users\Rana\Desktop\data\Neutral\" + inputfile.Substring(28, 8) + ".mp3"; pictureBox2.Image = Image.FromFile("C:\\Users\\Rana\\Documents\\Visual Studio 2015\\Projects\\proj4 - Copy\\proj2\\neutral.png"); label3.Text = "Neutral"; } } } } } } if (faces != null) { foreach (PropertyInfo prop in typeof(Affdex.Emotions).GetProperties()) { float value = (float)prop.GetValue(face.Emotions, null); string output = string.Format("{0}:{1:N2}", prop.Name, value); System.Console.WriteLine(output); } } } frame.Dispose(); } }