AForge.NET

Testimonials
Features
Samples
Tools
Documentation
License
Downloads
Sources
Discussions
Partners
Projects
Members
Donate

AForge.NET Framework
2.2.4 version is available!

Motion Detection

The page describes deprecated features, which are available only in 1.7.0 version of the framework. Visit the next page for information about new motion detection classes.

AForge.NET framework provides set of classes aimed to do motion detection in video streams. All the classes implement fairly simple and common interface, which is actually not bound to any specific video stream format/protocol. Instead of this, these classes just analyze consequent video frames given by user, which makes them free from any video processing routines and makes them applicable to any video stream format.

Different motion detection classes may use different algorithms to detect motion. But they are all similar in the way how they get video frames to analyze and how they report about detected motion level. All these class provide motion level property, which is the level of motion in the [0, 1] range. For example, if the property says 0.05, then it means that motion detection class has detected 5% motion level. Analyzing this property and comparing it with predefined threshold allows to raise alarm, when detected motion level is greater then the level which is considered to be safe.

Below is a simple code sample, which demonstrates main idea of working with different motion detector.

// create motion detector with noise suppresion
IMotionDetector detector = new ... (specific motion detection class)
// feed video frame to the detector
while ( !needToStop )
{
    // feed video frame
    detector.ProcessFrame( videoFrame );
    // check motion level
    if ( detector.MotionLevel > 0.01 )
    {
        // motion level is greater then 1% - fire alarm
        // make sound, start blinking, start saving video, etc.
        // ...
    }    
}
As the code shows, all we need to do is to feed new video frame and then check motion level. Note: user's code is responsible for reading video frames from particular stream, which makes motion detectors decoupled from video reading. See AForge.Video namespace for classes to access different video stream.

In addition to motion level detection, all motion detectors support highlighting of detected motion regions (can be turned on/off. But this really depends on particular detector, since highlighting may be done differently depending on algorithms use by detector.

Two frames difference motion detector
This type of motion detector is the simplest one and the quickest one. The idea of this detector is based on finding amount of difference in two consequent frames of video stream. The greater is difference, the greater is motion level. As it can be seen from the picture below, it does not suite very well those tasks, where it is required to precisely highlight moving object. However it has recommended itself very well for those tasks, which just require motion detection.
Two frames difference motion detector

Motion detectors based on background modeling
In contrast to the above motion detector, these motion detectors are based on finding difference between current video frame and a frame representing background. These motion detectors try to use simple techniques of modeling scene's background and updating it through time to get into account scene's changes. The background modeling feature of these motion detectors gives the ability of more precise highlighting of motion regions.

Below are demonstrated output of two versions of motion detectors based on background modeling. One does more precise highlight of moving objects' borders, but consumes more computational resources. Another one does less precise objects' highlight in the cost of requiring much less computational resources.
Background modeling and high precision highlight

Background modeling and low precision highlight

Counting motion detector
The counting motion detector is based on the same idea of background modeling as the above motion detectors. However after that it does additional processing and different object's highlighting. Once motion regions are identified, this detector uses blob counting algorithm to find rectangles of each detected moving object. This gives the ability to report about amount of detected objects, as well as position and size of each detected object (which are provided by additional properties of the motion detector class).

In addition to counting feature, this motion detector also supports rectangular zones of interest. It is possible to specify regions of video frames, where the algorithm should work on detecting motion. All the rest of video frame, which is not part of specified regions, is ignored and motion level is not reported for those parts.
Counting motion detector