我最近安装了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();
}
}
}
答案 0 :(得分:0)
我认为您正在查看错误的文档。您可以找到适用于Windows SDK here的正确文档。快速查看代码片段,您正在设置int camId = 10;
,这意味着探测器正在寻找系统上ID为10的Camera。默认情况下,内置摄像头具有id = 0
。我们将默认的CameraId设置为0,并将帧处理的速率设置为30.Here是CameraDetector的默认构造函数定义。
您可以使用此example分析相机Feed。我们还有一些准备好的应用程序可以在github上使用,主要是Affdex-Me和csharp-sample-apps。