我如何使affective调用我的回调函数

本文关键字:我的 回调 函数 调用 affective 何使 | 更新日期: 2023-09-27 18:11:46

我最近安装了Affectiva SDK (http://www.affectiva.com/),并按照教程分析来自相机的输入(http://developer.affectiva.com/v3/android/analyze-camera/)。不幸的是,这个项目似乎并不奏效。我的理解是,当检测到人脸等时,需要调用FaceListener, ImageListener, ProcessStatusListener的接口/回调函数(这是正确的吗)。

我没有得到任何错误,但是这些函数也从来没有被调用过(我把Console。WriteLine语句,以及在Visual Studio中放置断点)。不时地,一系列"Image Captured"语句被打印到控制台上,但我还不能重现这种情况发生的方式或原因。有人知道我做错了什么吗?提前感谢您的帮助。


下面是我目前为止的代码:

App.xaml.cs

using Affdex;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Affectiva
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application, FaceListener, ImageListener, ProcessStatusListener
    {
        public static CameraDetector detector;
        int camId = 10;
        int camFPS = 60;
        public App(){
            detector = new CameraDetector();
            String classifierPath = "C:''Program Files (x86)''Affectiva''Affdex SDK''data";
            detector.setClassifierPath(classifierPath);
            detector.setCameraId(camId);
            detector.setCameraFPS(camFPS);
            detector.setFaceListener(this);
            detector.setImageListener(this);
            detector.setProcessStatusListener(this);
            detector.setDetectSmile(true);
            detector.setDetectJoy(true);
            detector.setDetectAllExpressions(true);
            detector.setDetectAllEmotions(true);
            detector.setDetectAllEmojis(true);
            detector.setDetectAllAppearances(true);
        }
        public void onFaceFound(float f, int i)
        {
            Console.WriteLine("Face Found!");
        }
        public void onFaceLost(float f, int i)
        {
            Console.WriteLine("Face Lost!");
        }
        public void onImageResults(Dictionary<int, Face> faces, Frame f){
            Console.WriteLine("OnImageResults - " + faces.Count);
            if(faces.Count > 0)
                Console.WriteLine(faces.First().Value.Appearance.Age);
        }
        public void onImageCapture(Frame f){
            Console.WriteLine("Image Captured " + f.getHeight());
        }
        public void onProcessingFinished()
        {
            Console.WriteLine("Processing Finished");
        }
        public void onProcessingException(AffdexException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using WebEye.Controls.Wpf;
namespace Affectiva
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void OnStartButtonClick(object sender, RoutedEventArgs e)
        {
            var cameraId = webCameraControl.GetVideoCaptureDevices().First();
            webCameraControl.StartCapture(cameraId);
            App.detector.start();
        }
    }
}

我如何使affective调用我的回调函数

我想你看错文档了。您可以在这里找到Windows SDK的正确文档。快速查看一下代码片段,您正在设置int camId = 10;,这意味着检测器正在寻找系统上id为10的相机。默认情况下,内置摄像头有一个id = 0。我们将默认的CameraId设置为0,并将处理帧的速率设置为30。以下是CameraDetector的默认构造函数定义:

您可以使用此示例分析相机馈送。我们在github上也有一些现成的应用程序,主要是Affdex-Me和csharp-sample-apps。