Esempio n. 1
0
        static void Main(string[] args)
        {
            CmdOptions options = new CmdOptions();

            string[] opts = new string[args.Length + 2];

            for (int i = 0; i < args.Length; i++)
            {
                opts[i] = args[i];
            }

            opts = new string[4];
            //opts = new string[ 5 ];
            opts[0] = "-i";
            opts[1] = "camera";
            opts[2] = "-d";
            opts[3] = "C:\\Program Files\\Affectiva\\AffdexSDK\\data";
            //opts[4] = "-r";

            if (CommandLine.Parser.Default.ParseArguments(opts, options))
            {
                String dataFolder = options.DataFolder;

                if (options.Input.ToLower() != "camera")
                {
                    List <string> pathVideos = findVideos(options.Input, options.Extension);

                    foreach (string pVideo in pathVideos)
                    {
                        processVideo(pVideo, options);
                    }
                }
                else
                {
                    processCamera(dataFolder, options.recordCamera);
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }