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); } }
static void processVideo(String pVideo, CmdOptions options) { try { Affdex.Detector detector = null; List <string> imgExts = new List <string> { ".bmp", ".jpg", ".gif", ".png", ".jpe" }; List <string> vidExts = new List <string> { ".avi", ".mov", ".flv", ".webm", ".wmv", ".mp4" }; bool isImage = imgExts.Any <string>(s => (pVideo.Contains(s) || pVideo.Contains(s.ToUpper()))); if (isImage) { System.Console.WriteLine("Trying to process a bitmap image..." + options.Input.ToString()); detector = new Affdex.PhotoDetector((uint)options.numFaces, (Affdex.FaceDetectorMode)options.faceMode); } else { System.Console.WriteLine("Trying to process a video file..." + options.Input.ToString()); detector = new Affdex.VideoDetector(60F, (uint)options.numFaces, (Affdex.FaceDetectorMode)options.faceMode); } 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 = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName; if (Environment.OSVersion.Version.Major >= 6) { pV = Directory.GetParent(pV).ToString(); } Boolean research = false; StreamWriter outputFile = null; string Fname = Path.Combine(@pV, "blinkValues_" + DateTime.Now.ToString("yyMMdd_hhmmss") + ".txt"); string fileHeader = ""; fileHeader += "Blink\tEye-Aspect-Rate\t"; fileHeader += "frame"; System.Console.WriteLine(fileHeader); outputFile = new StreamWriter(Fname); outputFile.WriteLine(fileHeader); ProcessVideo videoForm = new ProcessVideo(detector, 15); videoForm.setOutputVideoFileLog(outputFile); detector.setClassifierPath(options.DataFolder); detector.setDetectAllEmotions(true); detector.setDetectAllExpressions(true); detector.setDetectAllEmojis(true); detector.setDetectAllAppearances(true); detector.start(); System.Console.WriteLine("Face detector mode = " + detector.getFaceDetectorMode().ToString()); if (isImage) { Affdex.Frame img = LoadFrameFromFile(options.Input); ((Affdex.PhotoDetector)detector).process(img); } else { ((Affdex.VideoDetector)detector).process(options.Input); } videoForm.ShowDialog(); videoForm.Dispose(); //videoForm = null; outputFile.Close(); detector.stop(); detector.Dispose(); } } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); } }