如何使用AForge设置运动检测?

时间:2009-12-19 19:05:17

标签: .net image-processing video-streaming motion-detection aforge

我正在尝试使用AForge.NET框架设置动作检测。我正在使用this页面上提供的信息。

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

但是,当我运行下面的代码时,我收到一个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 个答案:

答案 0 :(得分:1)

看一下BlobCountingObjectsProcessing motionProcessor,看来你已经将变量声明了两次,一次没有初始化并且一次初始化。

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

我认为这是你的NullReferenceException的来源。

相关问题