Table of Contents

Class BackgroundSubtractorMOG2

Namespace
Emgu.CV
Assembly
Emgu.CV.dll

The class implements the following algorithm: "Improved adaptive Gaussian mixture model for background subtraction" Z.Zivkovic International Conference Pattern Recognition, UK, August, 2004. http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf

public class BackgroundSubtractorMOG2 : UnmanagedObject, IDisposable, IBackgroundSubtractor, IAlgorithm
Inheritance
BackgroundSubtractorMOG2
Implements
Inherited Members
Extension Methods

Constructors

BackgroundSubtractorMOG2(int, float, bool)

Create an "Improved adaptive Gaussian mixture model for background subtraction".

public BackgroundSubtractorMOG2(int history = 500, float varThreshold = 16, bool shadowDetection = true)

Parameters

history int

The length of the history.

varThreshold float

The maximum allowed number of mixture components. Actual number is determined dynamically per pixel.

shadowDetection bool

If true, the algorithm will detect shadows and mark them. It decreases the speed a bit, so if you do not need this feature, set the parameter to false.

Properties

AlgorithmPtr

Pointer to the unmanaged Algorithm object

public nint AlgorithmPtr { get; }

Property Value

nint

BackgroundRatio

If a foreground pixel keeps semi-constant value for about backgroundRatio * history frames, it's considered background and added to the model as a center of a new component. It corresponds to TB parameter in the paper.

public double BackgroundRatio { get; set; }

Property Value

double

BackgroundSubtractorPtr

Pointer to the unmanaged BackgroundSubtractor object

public nint BackgroundSubtractorPtr { get; }

Property Value

nint

ComplexityReductionThreshold

The maximum variance

public double ComplexityReductionThreshold { get; set; }

Property Value

double

DetectShadows

If true, the algorithm detects shadows and marks them.

public bool DetectShadows { get; set; }

Property Value

bool

History

The number of last frames that affect the background model

public int History { get; set; }

Property Value

int

NMixtures

The number of gaussian components in the background model

public int NMixtures { get; set; }

Property Value

int

ShadowThreshold

A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel is more than twice darker then it is not shadow.

public double ShadowThreshold { get; set; }

Property Value

double

ShadowValue

Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0 in the mask always means background, 255 means foreground.

public int ShadowValue { get; set; }

Property Value

int

VarInit

Tg=3*3=9 is default. A smaller Tg value generates more components. A higher Tg value may result in a small number of components but they can grow too large.

public double VarInit { get; set; }

Property Value

double

VarMax

The minimum variance

public double VarMax { get; set; }

Property Value

double

VarMin

The initial variance of each gaussian component

public double VarMin { get; set; }

Property Value

double

VarThreshold

The main threshold on the squared Mahalanobis distance to decide if the sample is well described by the background model or not. Related to Cthr from the paper.

public double VarThreshold { get; set; }

Property Value

double

VarThresholdGen

The variance threshold for the pixel-model match used for new mixture component generation. Threshold for the squared Mahalanobis distance that helps decide when a sample is close to the existing components (corresponds to Tg in the paper). If a pixel is not close to any component, it is considered foreground or added as a new component. 3 sigma =%gt

public double VarThresholdGen { get; set; }

Property Value

double

Methods

DisposeObject()

Release all the unmanaged memory associated with this background model.

protected override void DisposeObject()