示例#1
0
        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);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Affdex.Detector detector = new Affdex.CameraDetector(0, 30, 30, 3, Affdex.FaceDetectorMode.LARGE_FACES);
            Form1           feed     = new Form1(detector);

            detector.setClassifierPath("E:\\Ufpel\\TCC\\APIs\\AffdexSDK\\data");
            detector.setDetectAllEmotions(true);
            detector.setDetectAllEmojis(true);
            detector.start();
            feed.ShowDialog();
            detector.stop();
        }
        private void StopCameraProcessing()
        {
            try
            {
                if ((mCameraDetector != null) && (mCameraDetector.isRunning()))
                {
                    mCameraDetector.stop();
                    mCameraDetector.Dispose();
                    mCameraDetector = null;
                }

                // Enable/Disable buttons on start
                btnStartCamera.IsEnabled    = true;
                btnResetCamera.IsEnabled    =
                    btnStopCamera.IsEnabled = false;
            }
            catch (Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
        /// <summary>
        ///
        /// </summary>
        private void InitializeCameraApp()
        {
            try
            {
                mCameraDetector = null;

                // Initialize Button Click Handlers
                btnStartCamera.Click      += btnStartCamera_Click;
                btnStopCamera.Click       += btnStopCamera_Click;
                btnShowPoints.Click       += btnShowPoints_Click;
                btnShowMeasurements.Click += btnShowMeasurements_Click;
                btnResetCamera.Click      += btnResetCamera_Click;
                btnExit.Click             += btnExit_Click;

                // Disable Stop/Reset buttons
                btnResetCamera.IsEnabled    =
                    btnStopCamera.IsEnabled = false;

                mFeaturePointsSkipCount         =
                    mCachedSkipFaceResultsCount = 0;

                // Initially hide Classifier Panels
                stackPanelLogoBackground.Visibility            =
                    stackPanelClassifiersBackground.Visibility =
                        stackPanelClassifiers.Visibility       = Visibility.Hidden;

                // Face Points are off by default
                mShowFacePoints   = false;
                mShowMeasurements = false;

                // Show the logo
                imgAffdexLogoDisplay.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
示例#5
0
        /// <summary>
        /// Starts the camera processing.
        /// </summary>
        private void StartCameraProcessing()
        {
            try
            {
                btnStartCamera.IsEnabled = false;
                btnResetCamera.IsEnabled =
                Points.IsEnabled =
                Metrics.IsEnabled =
                Appearance.IsEnabled =
                Emojis.IsEnabled =
                btnStopCamera.IsEnabled =
                btnAppShot.IsEnabled = 
                btnExit.IsEnabled = true;

                // Instantiate CameraDetector using default camera ID
                const int cameraId = 0;
                const int numberOfFaces = 10;
                const int cameraFPS = 15;
                const int processFPS = 15;
                Detector = new Affdex.CameraDetector(cameraId, cameraFPS, processFPS, numberOfFaces, Affdex.FaceDetectorMode.LARGE_FACES);

                //Set location of the classifier data files, needed by the SDK
                Detector.setClassifierPath(FilePath.GetClassifierDataFolder());

                // Set the Classifiers that we are interested in tracking
                TurnOnClassifiers();

                Detector.setImageListener(this);
                Detector.setProcessStatusListener(this);

                Detector.start();

                // Hide the logo, show the camera feed and the data canvas
                logoBackground.Visibility = Visibility.Hidden;
                cornerLogo.Visibility = Visibility.Visible;
                canvas.Visibility = Visibility.Visible;
                cameraDisplay.Visibility = Visibility.Visible;
            }
            catch (Affdex.AffdexException ex)
            {
                if (!String.IsNullOrEmpty(ex.Message))
                {
                    // If this is a camera failure, then reset the application to allow the user to turn on/enable camera
                    if (ex.Message.Equals("Unable to open webcam."))
                    {
                        MessageBoxResult result = MessageBox.Show(ex.Message,
                                                                "AffdexMe Error",
                                                                MessageBoxButton.OK,
                                                                MessageBoxImage.Error);
                        StopCameraProcessing();
                        return;
                    }
                }

                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
            catch (Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            CmdOptions options = new CmdOptions();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                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 isCamera = (options.Input.ToLower() == "camera");
                bool isImage  = imgExts.Any <string>(s => (options.Input.Contains(s) || options.Input.Contains(s.ToUpper())));
                bool isVideo  = (!isImage && !isCamera);

                if (isCamera)
                {
                    System.Console.WriteLine("Trying to process a camera feed...");
                    detector = new Affdex.CameraDetector(0, 30, 30, (uint)options.numFaces, (Affdex.FaceDetectorMode)options.faceMode);
                }
                else 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 if (isVideo)
                {
                    System.Console.WriteLine("Trying to process a video file..." + options.Input.ToString());
                    detector = new Affdex.VideoDetector(15, (uint)options.numFaces, (Affdex.FaceDetectorMode)options.faceMode);
                }
                else
                {
                    System.Console.WriteLine("File-Type not supported.");
                }


                if (detector != null)
                {
                    ProcessVideo videoForm = new ProcessVideo(detector);
                    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 (isVideo)
                    {
                        ((Affdex.VideoDetector)detector).process(options.Input);
                    }
                    else if (isImage)
                    {
                        ((Affdex.PhotoDetector)detector).process(LoadFrameFromFile(options.Input));
                    }
                    else
                    {
                        ;
                    }

                    videoForm.ShowDialog();
                    detector.stop();

                    //Hifza
                    //close socket after data transfer is complete
                    myNetworks.myNetwork.CloseClient();
                }
            }
        }
        private void StopCameraProcessing()
        {
            try
            {
                if ((mCameraDetector != null) && (mCameraDetector.isRunning()))
                {
                    mCameraDetector.stop();
                    mCameraDetector.Dispose();
                    mCameraDetector = null;
                }

                // Enable/Disable buttons on start
                btnStartCamera.IsEnabled = true;
                btnResetCamera.IsEnabled =
                btnStopCamera.IsEnabled = false;

            }
            catch(Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
        private void StartCameraProcessing()
        {
            try
            {
                btnStartCamera.IsEnabled = false;
                btnResetCamera.IsEnabled =
                btnShowPoints.IsEnabled =
                btnStopCamera.IsEnabled =
                btnExit.IsEnabled = true;

                // Instantiate CameraDetector using default camera ID
                mCameraDetector = new Affdex.CameraDetector();
                
                mCameraDetector.setClassifierPath(GetClassifierDataFolder());

                // Set the Classifiers that we are interested in tracking
                TurnOnClassifiers();

                // Initialize Classifier cache
                for (int index = 0; index < mAffdexClassifierValues.Count(); index++)
                {
                    mAffdexClassifierValues[index] = 0;
                }

                mCachedSkipFaceResultsCount = 0;
                mCameraDetector.setImageListener(this);
                mCameraDetector.setProcessStatusListener(this);



                // Set the License Path
                mCameraDetector.setLicensePath(GetAffdexLicense());
                
                mStartTime = DateTime.Now;
                mCameraDetector.start();

                // Delay loading the Classifier panel until 1st face
                mFirstFaceRecognized = false;

                // Hide the logo
                imgAffdexLogoDisplay.Visibility = Visibility.Hidden;
            }
            catch(Affdex.AffdexException ex)
            {
                if (!String.IsNullOrEmpty(ex.Message))
                {
                    // If this is a camera failure, then reset the application to allow the user to turn on/enable camera
                    if (ex.Message.Equals("Unable to open webcam."))
                    {
                        MessageBoxResult result = MessageBox.Show(ex.Message,
                                                                "AffdexMe Error",
                                                                MessageBoxButton.OK,
                                                                MessageBoxImage.Error);
                        StopCameraProcessing();
                        return;
                    }
                }

                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
            catch(Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private void InitializeCameraApp()
        {
            try
            {
                mCameraDetector = null;

                // Initialize Button Click Handlers
                btnStartCamera.Click += btnStartCamera_Click;
                btnStopCamera.Click += btnStopCamera_Click;
                btnShowPoints.Click += btnShowPoints_Click;
                btnShowMeasurements.Click += btnShowMeasurements_Click;
                btnResetCamera.Click += btnResetCamera_Click;
                btnExit.Click += btnExit_Click;

                // Disable Stop/Reset buttons
                btnResetCamera.IsEnabled =
                btnStopCamera.IsEnabled = false;

                mFeaturePointsSkipCount =
                mCachedSkipFaceResultsCount = 0;

                // Initially hide Classifier Panels
                stackPanelLogoBackground.Visibility =
                stackPanelClassifiersBackground.Visibility =
                stackPanelClassifiers.Visibility = Visibility.Hidden;

                // Face Points are off by default
                mShowFacePoints = false;
                mShowMeasurements = false;

                // Show the logo
                imgAffdexLogoDisplay.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
        private void StartCameraProcessing()
        {
            try
            {
                btnStartCamera.IsEnabled        = false;
                btnResetCamera.IsEnabled        =
                    btnShowPoints.IsEnabled     =
                        btnStopCamera.IsEnabled =
                            btnExit.IsEnabled   = true;

                // Instantiate CameraDetector using default camera ID
                mCameraDetector = new Affdex.CameraDetector();

                mCameraDetector.setClassifierPath(GetClassifierDataFolder());

                // Set the Classifiers that we are interested in tracking
                TurnOnClassifiers();

                // Initialize Classifier cache
                for (int index = 0; index < mAffdexClassifierValues.Count(); index++)
                {
                    mAffdexClassifierValues[index] = 0;
                }

                mCachedSkipFaceResultsCount = 0;
                mCameraDetector.setImageListener(this);
                mCameraDetector.setProcessStatusListener(this);



                // Set the License Path
                mCameraDetector.setLicensePath(GetAffdexLicense());

                mStartTime = DateTime.Now;
                mCameraDetector.start();

                // Delay loading the Classifier panel until 1st face
                mFirstFaceRecognized = false;

                // Hide the logo
                imgAffdexLogoDisplay.Visibility = Visibility.Hidden;
            }
            catch (Affdex.AffdexException ex)
            {
                if (!String.IsNullOrEmpty(ex.Message))
                {
                    // If this is a camera failure, then reset the application to allow the user to turn on/enable camera
                    if (ex.Message.Equals("Unable to open webcam."))
                    {
                        MessageBoxResult result = MessageBox.Show(ex.Message,
                                                                  "AffdexMe Error",
                                                                  MessageBoxButton.OK,
                                                                  MessageBoxImage.Error);
                        StopCameraProcessing();
                        return;
                    }
                }

                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
            catch (Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }
        /// <summary>
        /// Starts the camera processing.
        /// </summary>
        private void StartCameraProcessing()
        {
            try
            {
                btnStartCamera.IsEnabled                      = false;
                btnResetCamera.IsEnabled                      =
                    Points.IsEnabled                          =
                        Metrics.IsEnabled                     =
                            Appearance.IsEnabled              =
                                Emojis.IsEnabled              =
                                    btnStopCamera.IsEnabled   =
                                        btnAppShot.IsEnabled  =
                                            btnExit.IsEnabled = true;

                // Instantiate CameraDetector using default camera ID
                const int cameraId      = 0;
                const int numberOfFaces = 10;
                const int cameraFPS     = 15;
                const int processFPS    = 15;
                Detector = new Affdex.CameraDetector(cameraId, cameraFPS, processFPS, numberOfFaces, Affdex.FaceDetectorMode.LARGE_FACES);

                //Set location of the classifier data files, needed by the SDK
                Detector.setClassifierPath(FilePath.GetClassifierDataFolder());

                // Set the Classifiers that we are interested in tracking
                TurnOnClassifiers();

                Detector.setImageListener(this);
                Detector.setProcessStatusListener(this);

                Detector.start();

                // Hide the logo, show the camera feed and the data canvas
                logoBackground.Visibility = Visibility.Hidden;
                cornerLogo.Visibility     = Visibility.Visible;
                canvas.Visibility         = Visibility.Visible;
                cameraDisplay.Visibility  = Visibility.Visible;
            }
            catch (Affdex.AffdexException ex)
            {
                if (!String.IsNullOrEmpty(ex.Message))
                {
                    // If this is a camera failure, then reset the application to allow the user to turn on/enable camera
                    if (ex.Message.Equals("Unable to open webcam."))
                    {
                        MessageBoxResult result = MessageBox.Show(ex.Message,
                                                                  "AffdexMe Error",
                                                                  MessageBoxButton.OK,
                                                                  MessageBoxImage.Error);
                        StopCameraProcessing();
                        return;
                    }
                }

                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
            catch (Exception ex)
            {
                String message = String.IsNullOrEmpty(ex.Message) ? "AffdexMe error encountered." : ex.Message;
                ShowExceptionAndShutDown(message);
            }
        }