static void processCamera(String trainingDataFolder, bool record) { try { Affdex.Detector detector = null; System.Console.WriteLine("Trying to process a camera feed..."); double FPS = 30.0D; uint faceNo = 1; Affdex.FaceDetectorMode faceLarge = Affdex.FaceDetectorMode.LARGE_FACES; detector = new Affdex.CameraDetector(0, FPS, FPS, faceNo, faceLarge); if (detector != null) { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; string pV = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (Environment.OSVersion.Version.Major >= 6) { pV = Directory.GetParent(pV).ToString(); } string Fname = Path.Combine(@pV, "video_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".avi"); ProcessVideo videoForm = new ProcessVideo(detector, FPS); if (record) { videoForm.setOutputVideoFile(Fname); } detector.setClassifierPath(trainingDataFolder); detector.setDetectAllEmotions(true); detector.setDetectAllExpressions(true); detector.setDetectAllEmojis(true); detector.setDetectAllAppearances(true); detector.start(); System.Console.WriteLine("Face detector mode = " + detector.getFaceDetectorMode().ToString()); videoForm.ShowDialog(); videoForm.Dispose(); /* * detector.stop(); * detector.Dispose(); */ } } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); } }
/*private Affdex.Frame LoadFrameFromFile(string fileName) * { * Bitmap bitmap = new Bitmap(fileName); * * // Lock the bitmap's bits. * Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); * BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat); * * // Get the address of the first line. * IntPtr ptr = bmpData.Scan0; * * // Declare an array to hold the bytes of the bitmap. * int numBytes = bitmap.Width * bitmap.Height * 3; * byte[] rgbValues = new byte[numBytes]; * * int data_x = 0; * int ptr_x = 0; * int row_bytes = bitmap.Width * 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 < bitmap.Height; y++) * { * Marshal.Copy(ptr + ptr_x, rgbValues, data_x, row_bytes);//(pixels, data_x, ptr + ptr_x, row_bytes); * data_x += row_bytes; * ptr_x += bmpData.Stride; * } * * bitmap.UnlockBits(bmpData); * * return new Affdex.Frame(bitmap.Width, bitmap.Height, rgbValues, Affdex.Frame.COLOR_FORMAT.BGR); * }*/ private void restart_mode() { if (initialized) { //if (videoSurface != null) // videoSurface.Close(); Affdex.FaceDetectorMode FaceDeteMode = largeFacesCheckBox.Checked ? Affdex.FaceDetectorMode.LARGE_FACES : Affdex.FaceDetectorMode.SMALL_FACES; if (modeChecListkbox.SelectedIndex == 0) { detector = new Affdex.CameraDetector((int)camIDNumericUpDown.Value, (double)camFPSNumericUpDown.Value, (double)camFPSNumericUpDown.Value, (uint)numFacesNumericUpDown.Value, FaceDeteMode); } else if (modeChecListkbox.SelectedIndex == 1) { detector = new Affdex.PhotoDetector((uint)numFacesNumericUpDown.Value, FaceDeteMode); } else if (modeChecListkbox.SelectedIndex == 2) { detector = new Affdex.VideoDetector(30, (uint)numFacesNumericUpDown.Value, FaceDeteMode); } //detector.setClassifierPath("C:\\Program Files\\Affectiva\\AffdexSDK\\data"); detector.setClassifierPath(Directory.GetCurrentDirectory() + "\\affectiva_SDK_data"); detector.setDetectAllEmotions(true); detector.setDetectAllExpressions(false); detector.setDetectAllEmojis(false); detector.setDetectAllAppearances(false); detector.start(); //System.Console.WriteLine("Face detector mode = " + detector.getFaceDetectorMode().ToString()); //if (modeCheckbox.SelectedIndex == 2) ((Affdex.VideoDetector)detector).process(options.Input); //else if (modeCheckbox.SelectedIndex == 1) ((Affdex.PhotoDetector)detector).process(LoadFrameFromFile(options.Input)); MainForm affForm = new MainForm(detector); affForm.Show(); //detector.stop(); } }