title: How to setup motion detection using AForge?
body: <p>i'm trying to setup motiondetection using the AForge.NET framework. I'm using the information provided on <a href="http://www.aforgenet.com/framework/features/motion_detection_2.0.html" rel="nofollow noreferrer">this</a> page.</p>
  
  <p>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).</p>
  
  <p>However, when I run the code below I receive a NullReferenceException. What am I missing?</p>
  
  <pre><code>    // New frame received by the player
      private void videoSourcePlayer_NewFrame( object sender, ref Bitmap image )
      {
          if (this.detector.ProcessFrame(image) &gt; 0.02)
          {
              Console.WriteLine("Motion");
          }
          else
          {
              Console.WriteLine("No motion");
          }
      }
  </code></pre>
  
  <p>The <code>detector</code> is initialized as private class variable when a videostream is chosen.</p>
  
  <pre><code>    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);
      }
  </code></pre>