2016-10-18 70 views
1

我刚开始使用C#的Affectiva SDK,经过几次运行后,我偶然发现了一个连续的崩溃问题。 我正在使用相机处理,在x86架构和.Net 4.5.1上。我有VS 2013安装。我的操作系统是Windows 10.我在输出中添加了“opencv_ffmpeg248”和“affdex-native”。 代码构建并运行正常,但有时在运行时会引发此错误并关闭应用程序。Affectiva C#SDK崩溃

这是我使用的代码:

public class Class1 : Affdex.ImageListener 
{ 
    private Affdex.CameraDetector _detector; 

    public event EventHandler<string[]> AllValuesEvent; 

    public Class1() 
    { 
     _detector = new Affdex.CameraDetector(); 
     _detector.setDetectAllEmotions(true); 
     _detector.setDetectAllAppearances(true); 

     String classifierPath = @"C:\Program Files (x86)\Affectiva\Affdex SDK\data"; 
     _detector.setClassifierPath(classifierPath); 
     _detector.setImageListener(this); 
     _detector.start(); 
    } 

    public void StopCamera() 
    { 
     _detector.stop(); 
    } 


    public void onImageCapture(Frame frame) 
    { 

    } 

    public void onImageResults(Dictionary<int, Face> faces, Frame frame) 
    { 
     if (faces.Count > 0) 
     { 
      Face face = faces.First().Value; 

      Console.WriteLine("Age: {0} Gender: {1} Glasses: {2}", 
       face.Appearance.Age, 
       face.Appearance.Gender, 
       face.Appearance.Glasses); 

      string[] names = new string[8]; 
      string[] values = new string[8]; 

      names[0] = "Anger"; 
      names[1] = "Contempt"; 
      names[2] = "Disgust"; 
      names[3] = "Engagement"; 
      names[4] = "Fear"; 
      names[5] = "Joy"; 
      names[6] = "Sadness"; 
      names[7] = "Surprise"; 

      values[0] = face.Emotions.Anger.ToString("F2"); 
      values[1] = face.Emotions.Contempt.ToString("F2"); 
      values[2] = face.Emotions.Disgust.ToString("F2"); 
      values[3] = face.Emotions.Engagement.ToString("F2"); 
      values[4] = face.Emotions.Fear.ToString("F2"); 
      values[5] = face.Emotions.Joy.ToString("F2"); 
      values[6] = face.Emotions.Sadness.ToString("F2"); 
      values[7] = face.Emotions.Surprise.ToString("F2"); 

      RaiseAllValuesEvent(names, values); 
     } 
    } 

    private void RaiseAllValuesEvent(string[] names, string[] values) 
    { 
     if (AllValuesEvent != null) 
     { 
      AllValuesEvent(names, values); 
     } 
    } 
} 

这些是出现错误: enter image description here enter image description here

任何人有什么建议吗?

非常感谢。

+3

嘿,一个问题可能是您正在混合调试和发布dll。您可以确保您导入与您的构建配置文件匹配的dll。 – ahamino

+0

显然,你的建议似乎解决了我的问题。 我将在接下来的几天继续监视它,看看我是否仍然使用发布DLL获取错误并返回结果。 –

+0

你好, @ahamino你的建议解决了我的问题。谢谢。我不知道如何标记你的评论作为答案。 –

回答

1

我在这里发布此信息,以便能够标记为答案,并关闭此主题。

正如@ahamino在评论中所建议的,问题在于我不小心将调试dll混入了我的引用。仅添加发布dll修复了我的问题。

再次感谢你@ahamino。