我最近安装了 Affectiva SDK ( http://www.affectiva.com/ ) 并按照教程分析来自相机的输入 ( http://developer.affectiva.com/v3/android/analyze-camera/ )。不幸的是,该项目似乎没有奏效。据我了解,FaceListener, ImageListener, ProcessStatusListener
当检测到人脸时需要调用接口/回调函数等(这是正确的)。
我没有收到任何错误,但这些函数也从未被调用(我已经在其中放置了 Console.WriteLine 语句,并在 Visual Studio 中放置了断点)。有时,控制台会打印出一系列“图像捕获”语句,但我还无法重现这种情况的发生方式或原因。有谁知道我做错了什么?预先感谢您的任何帮助。
到目前为止,以下是我的代码:
应用程序.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);
}
}
}
主窗口.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();
}
}
}