C# Класс AForge.Vision.Motion.CustomFrameDifferenceDetector

Motion detector based on difference with predefined background frame.

The class implements motion detection algorithm, which is based on difference of current video frame with predefined 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.

In the case if custom background frame is not specified by using SetBackgroundFrame(Bitmap) method, the algorithm takes first video frame as a background frame and calculates difference of further video frames with it.

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.

Sample usage:

// create motion detector MotionDetector detector = new MotionDetector( new CustomFrameDifferenceDetector( ), 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 } }
Наследование: IMotionDetector
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
CustomFrameDifferenceDetector ( ) : System

Initializes a new instance of the CustomFrameDifferenceDetector class.

CustomFrameDifferenceDetector ( bool suppressNoise ) : System

Initializes a new instance of the CustomFrameDifferenceDetector class.

CustomFrameDifferenceDetector ( bool suppressNoise, bool keepObjectEdges ) : System

Initializes a new instance of the CustomFrameDifferenceDetector class.

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.

In the case if custom background frame was set using SetBackgroundFrame(Bitmap) method, this method does not reset it. The method resets only automatically generated background frame.

SetBackgroundFrame ( Bitmap backgroundFrame ) : void

Set background frame.

The method sets background frame, which will be used to calculate difference with.

SetBackgroundFrame ( BitmapData backgroundFrame ) : void

Set background frame.

The method sets background frame, which will be used to calculate difference with.

SetBackgroundFrame ( UnmanagedImage backgroundFrame ) : void

Set background frame.

The method sets background frame, which will be used to calculate difference with.

Приватные методы

Метод Описание
Reset ( bool force ) : void

Описание методов

CustomFrameDifferenceDetector() публичный Метод

Initializes a new instance of the CustomFrameDifferenceDetector class.
public CustomFrameDifferenceDetector ( ) : System
Результат System

CustomFrameDifferenceDetector() публичный Метод

Initializes a new instance of the CustomFrameDifferenceDetector class.
public CustomFrameDifferenceDetector ( bool suppressNoise ) : System
suppressNoise bool Suppress noise in video frames or not (see property).
Результат System

CustomFrameDifferenceDetector() публичный Метод

Initializes a new instance of the CustomFrameDifferenceDetector class.
public CustomFrameDifferenceDetector ( 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).
Результат System

ProcessFrame() публичный Метод

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).
Результат void

Reset() публичный Метод

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.

In the case if custom background frame was set using SetBackgroundFrame(Bitmap) method, this method does not reset it. The method resets only automatically generated background frame.

public Reset ( ) : void
Результат void

SetBackgroundFrame() публичный Метод

Set background frame.

The method sets background frame, which will be used to calculate difference with.

public SetBackgroundFrame ( Bitmap backgroundFrame ) : void
backgroundFrame System.Drawing.Bitmap Background frame to set.
Результат void

SetBackgroundFrame() публичный Метод

Set background frame.

The method sets background frame, which will be used to calculate difference with.

public SetBackgroundFrame ( BitmapData backgroundFrame ) : void
backgroundFrame System.Drawing.Imaging.BitmapData Background frame to set.
Результат void

SetBackgroundFrame() публичный Метод

Set background frame.

The method sets background frame, which will be used to calculate difference with.

public SetBackgroundFrame ( UnmanagedImage backgroundFrame ) : void
backgroundFrame AForge.Imaging.UnmanagedImage Background frame to set.
Результат void