C# Class AForge.Vision.Motion.SimpleBackgroundModelingDetector

Motion detector based on simple background modeling.

The class implements motion detection algorithm, which is based on difference of current video frame with modeled background frame. The difference frame is thresholded and the amount of difference pixels is calculated. To suppress stand-alone noisy pixels erosion morphological operator may be applied, which is controlled by SuppressNoise property.

In the case if precise motion area's borders are required (for example, for further motion post processing), then KeepObjectsEdges property may be used to restore borders after noise suppression.

As the first approximation of background frame, the first frame of video stream is taken. During further video processing the background frame is constantly updated, so it changes in the direction to decrease difference with current video frame (the background frame is moved towards current frame). See FramesPerBackgroundUpdate MillisecondsPerBackgroundUpdate properties, which control the rate of background frame update.

Unlike TwoFramesDifferenceDetector motion detection algorithm, this algorithm allows to identify quite clearly all objects, which are not part of the background (scene) - most likely moving objects. And unlike CustomFrameDifferenceDetector motion detection algorithm, this algorithm includes background adaptation feature, which allows it to update its modeled background frame in order to take scene changes into account.

Because of the adaptation feature of the algorithm, it may adopt to background changes, what CustomFrameDifferenceDetector algorithm can not do. However, if moving object stays on the scene for a while (so algorithm adopts to it and does not treat it as a new moving object any more) and then starts to move again, the algorithm may find two moving objects - the true one, which is really moving, and the false one, which does not (the place, where the object stayed for a while).

The algorithm is not applicable to such cases, when moving object resides in camera's view most of the time (laptops camera monitoring a person sitting in front of it, for example). The algorithm is mostly supposed for cases, when camera monitors some sort of static scene, where moving objects appear from time to time - street, road, corridor, etc.

Sample usage:

// 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 } }
Inheritance: IMotionDetector
ファイルを表示 Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Public Methods

Method Description
ProcessFrame ( UnmanagedImage videoFrame ) : void

Process new video frame.

Processes new frame from video source and detects motion in it.

Check MotionLevel property to get information about amount of motion (changes) in the processed frame.

Reset ( ) : void

Reset motion detector to initial state.

Resets internal state and variables of motion detection algorithm. Usually this is required to be done before processing new video source, but may be also done at any time to restart motion detection algorithm.

SimpleBackgroundModelingDetector ( ) : System

Initializes a new instance of the SimpleBackgroundModelingDetector class.

SimpleBackgroundModelingDetector ( bool suppressNoise ) : System

Initializes a new instance of the SimpleBackgroundModelingDetector class.

SimpleBackgroundModelingDetector ( bool suppressNoise, bool keepObjectEdges ) : System

Initializes a new instance of the SimpleBackgroundModelingDetector class.

Method Details

ProcessFrame() public method

Process new video frame.

Processes new frame from video source and detects motion in it.

Check MotionLevel property to get information about amount of motion (changes) in the processed frame.

public ProcessFrame ( UnmanagedImage videoFrame ) : void
videoFrame AForge.Imaging.UnmanagedImage Video frame to process (detect motion in).
return void

Reset() public method

Reset motion detector to initial state.

Resets internal state and variables of motion detection algorithm. Usually this is required to be done before processing new video source, but may be also done at any time to restart motion detection algorithm.

public Reset ( ) : void
return void

SimpleBackgroundModelingDetector() public method

Initializes a new instance of the SimpleBackgroundModelingDetector class.
public SimpleBackgroundModelingDetector ( ) : System
return System

SimpleBackgroundModelingDetector() public method

Initializes a new instance of the SimpleBackgroundModelingDetector class.
public SimpleBackgroundModelingDetector ( bool suppressNoise ) : System
suppressNoise bool Suppress noise in video frames or not (see property).
return System

SimpleBackgroundModelingDetector() public method

Initializes a new instance of the SimpleBackgroundModelingDetector class.
public SimpleBackgroundModelingDetector ( bool suppressNoise, bool keepObjectEdges ) : System
suppressNoise bool Suppress noise in video frames or not (see property).
keepObjectEdges bool Restore objects edges after noise suppression or not (see property).
return System