AForge.NET

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

AForge.NET Framework
2.2.5 version is available!

Motion Detection

AForge.NET framework provides set of classes, which implement different motion detection and motion processing algorithms. Motion detection algorithms are aimed only to detect motion in continuous video frames providing amount of detected motion and motion frame - binary image, which shows all regions where motion is detected. Motion processing algorithms are aimed to perform post processing of detected motion - highlight motion regions, count moving objects, track them, etc.

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 classes 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 detection and motion processing algorithms:

// create motion detector
MotionDetector detector = new MotionDetector(
    new SimpleBackgroundModelingDetector( ),
    new MotionAreaHighlighting( ) );
// continuously feed video frames to motion detector
while ( ... )
{
    // process new video frame and check motion level
    if ( detector.ProcessFrame( videoFrame ) > 0.02 )
    {
        // ring alarm or do somethng else
    }
}
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 streams.

Motion Detection Algorithms

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

Simple background modeling motion detector
In contrast to the above mentioned motion detector, this motion detector is based on finding difference between current video frame and a frame representing background. This motion detector tries 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 this motion detector gives the ability of more precise highlighting of motion regions.
Simple background modeling motion detector

Custom frame difference motion detector
This class implements motion detection algorithm, which is based on the difference of current video frame with predefined background frame, which puts it in-between of the two above classes. On the one hand this motion detector is based on simple differencing as the two frames difference motion detector, which makes it fast. On the other hand it does differencing of current video frame with background frame, which may allow finding moving objects, but not areas of changes (like in simple background modeling motion detector). However, user needs to specify background frame on his own (or the algorithm will take first video frame as a background frame) and the algorithm will never try to update it, which means no adaptation to scene changes.

Motion Processing Algorithms

Motion area highlighting
This motion processing algorithm is aimed just to highlight motion areas found by motion detection algorithm with specified color. All of the above screenshots demonstrate the work of motion are highlighting.

Motion border highlighting
This motion processing algorithm is aimed to highlight only borders of motion areas found by motion detection algorithm. It is supposed to be used only with those motion detection algorithms, which may accurately locate moving objects.
Motion border highlighting

Grid motion area processing
This motion processing algorithm allows to do grid processing of motion frame. This means that entire motion frame can be divided by a grid into certain amount of cells and motion level can be calculated for each cell individually, so you may know which part of the video frame had more motion. In addition this motion processing algorithm provides highlighting, which may be enabled or disable. User may specify threshold for cells' motion level to highlight.
Grid motion area processing

Blob counting objects processing
This motion processing algorithm allows counting separate objects in the motion frame, which is provided by motion detection algorithm. In addition it may also highlight detected objects with a rectangle of specified color. The algorithm counts and highlights only those objects, which size satisfies specified limits - it is possible to configure this motion processing algorithm to ignore objects smaller than specified size.

This motion processing algorithm is supposed to be used only with those motion detection algorithms, which may accurately locate moving objects.
Blob counting objects processing