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(); } }
/// <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); } }