예제 #1
0
        public void Initialize(Detector detector, int discrete)
        {
            WindowsNativePlatform.detector = detector;

            //load our lib!

            String adP = Application.streamingAssetsPath;

            String affdexDataPath = Path.Combine(adP, "affdex-data"); // Application.streamingAssetsPath + "/affdex-data";
            //String affdexDataPath = Application.dataPath + "/affdex-data";
            affdexDataPath = affdexDataPath.Replace('/', '\\');
            int status = initialize(discrete, affdexDataPath);
            Debug.Log("Initialized detector: " + status);

            FaceResults faceFound = new FaceResults(this.onFaceFound);
            FaceResults faceLost = new FaceResults(this.onFaceLost);
            ImageResults imageResults = new ImageResults(this.onImageResults);

            h1 = GCHandle.Alloc(faceFound, GCHandleType.Pinned);
            h2 = GCHandle.Alloc(faceLost, GCHandleType.Pinned);
            h3 = GCHandle.Alloc(imageResults, GCHandleType.Pinned);

            status = registerListeners(imageResults, faceFound, faceLost);
            Debug.Log("Registered listeners: " + status);
        }
예제 #2
0
        public Analyzer(string dataFolder = @".\data", int maxRecognizedFaces = 100, FaceDetectorMode faceDetectionMode = FaceDetectorMode.SMALL_FACES)
        {
            this.DataFolder         = dataFolder;
            this.MaxRecognizedFaces = maxRecognizedFaces;
            this.FaceDetectionMode  = faceDetectionMode;

            detector =
                new Affdex.PhotoDetector((uint)MaxRecognizedFaces, (Affdex.FaceDetectorMode)FaceDetectionMode);

            if (detector != null)
            {
                // ProcessVideo videoForm = new ProcessVideo(detector);
                detector.setClassifierPath(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)
                detector.setImageListener(this);
                detector.setProcessStatusListener(this);
                //videoForm.ShowDialog();
            }
        }
예제 #3
0
 public ProcessVideo(Affdex.Detector detector)
 {
     System.Console.WriteLine("Starting Interface...");
     this.detector = detector;
     detector.setImageListener(this);
     detector.setProcessStatusListener(this);
     InitializeComponent();
     rwLock = new ReaderWriterLock();
     this.DoubleBuffered  = true;
     this.FormBorderStyle = FormBorderStyle.FixedSingle;
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
 }
예제 #4
0
        /// <summary>
        /// Starts the camera processing.
        /// </summary>
        private void StartCameraProcessing()
        {
            try
            {
                // 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("C:\\Program Files\\Affectiva\\AffdexSDK\\data");

                //跟踪一些 我们预先设置的的分类器,比如开心,讨厌等等
                TurnOnClassifiers();

                Detector.setImageListener(AffdexListener);//设置两个监听
                Detector.setProcessStatusListener(AffdexListener);

                Detector.start();
            }
            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);
            }
        }
예제 #5
0
        protected GCHandle h1, h2, h3; //handles to unmanaged function pointer callbacks

        /// <summary>
        /// Initialize the detector.  Creates the instance for later calls
        /// </summary>
        /// <param name="discrete"></param>
        /// <param name="detector">Core detector object.  Handles all communication with the native APIs.</param>
        public abstract IEnumerator Initialize(Detector detector, int discrete);