views:

492

answers:

1

Hi,

i'm trying to setup motiondetection using the AForge.NET framework. I'm using the information provided on this page.

I've setup a DirectShow videostream which feeds a part of my desktop through a stream. I can choose this stream in the sample videoplayer project which is provided with AForge. (And I see my desktop through the player).

However, when I run the code below I receive a NullReferenceException. What am I missing?

    // 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");
        }
    }

The detector is initialized as private class variable when a videostream is chosen.

    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);
    }
A: 

Have a look at the BlobCountingObjectsProcessing motionProcessor, it seems you've declared the variable twice, once not initialized and once initialized.

One outside method scope and one inside method scope.

I think that's where your NullReferenceException is coming from.

Tony
correct :). I'm used to VB, stupid error haha
Ropstah