public void onImageResults(Dictionary <int, Affdex.Face> faces, Affdex.Frame frame) { process_fps = 1.0f / (frame.getTimestamp() - process_last_timestamp); process_last_timestamp = frame.getTimestamp(); System.Console.WriteLine(" pfps: {0}", process_fps.ToString()); byte[] pixels = frame.getBGRByteArray(); this.img = new Bitmap(frame.getWidth(), frame.getHeight(), PixelFormat.Format24bppRgb); var bounds = new Rectangle(0, 0, frame.getWidth(), frame.getHeight()); BitmapData bmpData = img.LockBits(bounds, ImageLockMode.WriteOnly, img.PixelFormat); IntPtr ptr = bmpData.Scan0; int data_x = 0; int ptr_x = 0; int row_bytes = frame.getWidth() * 3; // The bitmap requires bitmap data to be byte aligned. // http://stackoverflow.com/questions/20743134/converting-opencv-image-to-gdi-bitmap-doesnt-work-depends-on-image-size for (int y = 0; y < frame.getHeight(); y++) { Marshal.Copy(pixels, data_x, ptr + ptr_x, row_bytes); data_x += row_bytes; ptr_x += bmpData.Stride; } img.UnlockBits(bmpData); this.faces = faces; //rwLock.ReleaseWriterLock(); this.Invalidate(); frame.Dispose(); }
private void DrawCapturedImage(Affdex.Frame image) { var result = this.Dispatcher.BeginInvoke((Action)(() => { try { cameraDisplay.Source = ConstructImage(image.getBGRByteArray(), image.getWidth(), image.getHeight()); if (++DrawSkipCount > 4) { canvas.Faces = new Dictionary <int, Affdex.Face>(); canvas.InvalidateVisual(); DrawSkipCount = 0; } if (image != null) { image.Dispose(); } } catch (Exception ex) { String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message; ShowExceptionAndShutDown(message); } })); }
/// <summary> /// Draws the image captured from the camera. /// </summary> /// <param name="image">The image captured.</param> private void DrawCapturedImage(Affdex.Frame image) { // Update the Image control from the UI thread try { // Update the Image control from the UI thread //cameraDisplay.Source = rtb; pictureBox1.Image = BitmapFromSource(ConstructImage(image.getBGRByteArray(), image.getWidth(), image.getHeight())); // Allow N successive OnCapture callbacks before the FacePoint drawing canvas gets cleared. if (image != null) { image.Dispose(); } } catch (Exception ex) { String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message; // ShowExceptionAndShutDown(message); } }
public void onImageCapture(Affdex.Frame frame) { frame.Dispose(); }
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(); } }
public void onImageCapture(Affdex.Frame frame) { DrawCapturedImage(frame); frame.Dispose(); }