0

我想使用AForge.NET框架来设置motiondetection。我正在使用this页面上提供的信息。如何使用AForge设置动作检测?

我已经设置了一个DirectShow videostream,它通过一个流提供我的桌面的一部分。我可以在随AForge一起提供的示例视频播放器项目中选择此流。 (我通过播放器看到我的桌面)。

但是,当我运行下面的代码时,我收到一个NullReferenceException。我错过了什么?

// New frame received by the player 
    private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image) 
    { 
     if (this.detector.ProcessFrame(image) > 0.02) 
     { 
      Console.WriteLine("Motion"); 
     } 
     else 
     { 
      Console.WriteLine("No motion"); 
     } 
    } 

detector选择一个视频流时被初始化为私有类变量。

private MotionDetector detector; 
    private BlobCountingObjectsProcessing motionProcessor; 

    // Open video source 
    private void OpenVideoSource(IVideoSource source) 
    { 
     BlobCountingObjectsProcessing motionProcessor = new BlobCountingObjectsProcessing(); 

     MotionDetector detector = new MotionDetector(
      new SimpleBackgroundModelingDetector(), 
      motionProcessor); 
    } 

回答

1

有一个看BlobCountingObjectsProcessing motionProcessor,看来你已经声明的变量两次,一次没有初始化,初始化一次。

一个外部方法范围和一个内部方法范围。

我认为这就是你的NullReferenceException来自哪里。

+0

正确:)。我习惯了VB,愚蠢的错误哈哈 – Ropstah 2009-12-21 18:18:09