OpenCV for Unity 2.6.4
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.10.0/index.html ) for the details of the argument of the method.
Loading...
Searching...
No Matches
OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2 Class Reference

Gaussian Mixture-based Background/Foreground Segmentation Algorithm. More...

Public Member Functions

override void apply (Mat image, Mat fgmask)
 Computes a foreground mask.
 
override void apply (Mat image, Mat fgmask, double learningRate)
 Computes a foreground mask.
 
double getBackgroundRatio ()
 Returns the "background ratio" parameter of the algorithm.
 
double getComplexityReductionThreshold ()
 Returns the complexity reduction threshold.
 
bool getDetectShadows ()
 Returns the shadow detection flag.
 
int getHistory ()
 Returns the number of last frames that affect the background model.
 
int getNMixtures ()
 Returns the number of gaussian components in the background model.
 
double getShadowThreshold ()
 Returns the shadow threshold.
 
int getShadowValue ()
 Returns the shadow value.
 
double getVarInit ()
 Returns the initial variance of each gaussian component.
 
double getVarMax ()
 
double getVarMin ()
 
double getVarThreshold ()
 Returns the variance threshold for the pixel-model match.
 
double getVarThresholdGen ()
 Returns the variance threshold for the pixel-model match used for new mixture component generation.
 
void setBackgroundRatio (double ratio)
 Sets the "background ratio" parameter of the algorithm.
 
void setComplexityReductionThreshold (double ct)
 Sets the complexity reduction threshold.
 
void setDetectShadows (bool detectShadows)
 Enables or disables shadow detection.
 
void setHistory (int history)
 Sets the number of last frames that affect the background model.
 
void setNMixtures (int nmixtures)
 Sets the number of gaussian components in the background model.
 
void setShadowThreshold (double threshold)
 Sets the shadow threshold.
 
void setShadowValue (int value)
 Sets the shadow value.
 
void setVarInit (double varInit)
 Sets the initial variance of each gaussian component.
 
void setVarMax (double varMax)
 
void setVarMin (double varMin)
 
void setVarThreshold (double varThreshold)
 Sets the variance threshold for the pixel-model match.
 
void setVarThresholdGen (double varThresholdGen)
 Sets the variance threshold for the pixel-model match used for new mixture component generation.
 
- Public Member Functions inherited from OpenCVForUnity.VideoModule.BackgroundSubtractor
virtual void getBackgroundImage (Mat backgroundImage)
 Computes a background image.
 
- Public Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm
virtual void clear ()
 Clears the algorithm state.
 
virtual bool empty ()
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.
 
virtual string getDefaultName ()
 
IntPtr getNativeObjAddr ()
 
void save (string filename)
 
- Public Member Functions inherited from OpenCVForUnity.DisposableObject
void Dispose ()
 
void ThrowIfDisposed ()
 

Static Public Member Functions

static new BackgroundSubtractorMOG2 __fromPtr__ (IntPtr addr)
 
- Static Public Member Functions inherited from OpenCVForUnity.VideoModule.BackgroundSubtractor
static new BackgroundSubtractor __fromPtr__ (IntPtr addr)
 
- Static Public Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm
static Algorithm __fromPtr__ (IntPtr addr)
 
- Static Public Member Functions inherited from OpenCVForUnity.DisposableObject
static IntPtr ThrowIfNullIntPtr (IntPtr ptr)
 

Protected Member Functions

override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.VideoModule.BackgroundSubtractor
- Protected Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm
- Protected Member Functions inherited from OpenCVForUnity.DisposableOpenCVObject
 DisposableOpenCVObject ()
 
 DisposableOpenCVObject (bool isEnabledDispose)
 
 DisposableOpenCVObject (IntPtr ptr)
 
 DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)
 
override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableObject
 DisposableObject ()
 
 DisposableObject (bool isEnabledDispose)
 

Additional Inherited Members

- Package Functions inherited from OpenCVForUnity.VideoModule.BackgroundSubtractor
- Package Functions inherited from OpenCVForUnity.CoreModule.Algorithm
- Package Attributes inherited from OpenCVForUnity.DisposableOpenCVObject
- Properties inherited from OpenCVForUnity.DisposableObject
bool IsDisposed [get, protected set]
 
bool IsEnabledDispose [get, set]
 

Detailed Description

Gaussian Mixture-based Background/Foreground Segmentation Algorithm.

The class implements the Gaussian mixture model background subtraction described in [Zivkovic2004] and [Zivkovic2006] .

Member Function Documentation

◆ __fromPtr__()

static new BackgroundSubtractorMOG2 OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.__fromPtr__ ( IntPtr addr)
static

◆ apply() [1/2]

override void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.apply ( Mat image,
Mat fgmask )
virtual

Computes a foreground mask.

Parameters
imageNext video frame. Floating point frame will be used without scaling and should be in range \([0,255]\).
fgmaskThe output foreground mask as an 8-bit binary image.
learningRateThe value between 0 and 1 that indicates how fast the background model is learnt. Negative parameter value makes the algorithm to use some automatically chosen learning rate. 0 means that the background model is not updated at all, 1 means that the background model is completely reinitialized from the last frame.

Reimplemented from OpenCVForUnity.VideoModule.BackgroundSubtractor.

◆ apply() [2/2]

override void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.apply ( Mat image,
Mat fgmask,
double learningRate )
virtual

Computes a foreground mask.

Parameters
imageNext video frame. Floating point frame will be used without scaling and should be in range \([0,255]\).
fgmaskThe output foreground mask as an 8-bit binary image.
learningRateThe value between 0 and 1 that indicates how fast the background model is learnt. Negative parameter value makes the algorithm to use some automatically chosen learning rate. 0 means that the background model is not updated at all, 1 means that the background model is completely reinitialized from the last frame.

Reimplemented from OpenCVForUnity.VideoModule.BackgroundSubtractor.

◆ Dispose()

override void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.Dispose ( bool disposing)
protectedvirtual

◆ getBackgroundRatio()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getBackgroundRatio ( )

Returns the "background ratio" parameter of the algorithm.

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.

◆ getComplexityReductionThreshold()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getComplexityReductionThreshold ( )

Returns the complexity reduction threshold.

This parameter defines the number of samples needed to accept to prove the component exists. CT=0.05 is a default value for all the samples. By setting CT=0 you get an algorithm very similar to the standard Stauffer&Grimson algorithm.

◆ getDetectShadows()

bool OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getDetectShadows ( )

Returns the shadow detection flag.

If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorMOG2 for details.

◆ getHistory()

int OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getHistory ( )

Returns the number of last frames that affect the background model.

◆ getNMixtures()

int OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getNMixtures ( )

Returns the number of gaussian components in the background model.

◆ getShadowThreshold()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getShadowThreshold ( )

Returns the shadow threshold.

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. See Prati, Mikic, Trivedi and Cucchiara, Detecting Moving Shadows...*, IEEE PAMI,2003.

◆ getShadowValue()

int OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getShadowValue ( )

Returns the shadow value.

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.

◆ getVarInit()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getVarInit ( )

Returns the initial variance of each gaussian component.

◆ getVarMax()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getVarMax ( )

◆ getVarMin()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getVarMin ( )

◆ getVarThreshold()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getVarThreshold ( )

Returns the variance threshold for the pixel-model match.

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.

◆ getVarThresholdGen()

double OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.getVarThresholdGen ( )

Returns 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 => 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.

◆ setBackgroundRatio()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setBackgroundRatio ( double ratio)

Sets the "background ratio" parameter of the algorithm.

◆ setComplexityReductionThreshold()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setComplexityReductionThreshold ( double ct)

Sets the complexity reduction threshold.

◆ setDetectShadows()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setDetectShadows ( bool detectShadows)

Enables or disables shadow detection.

◆ setHistory()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setHistory ( int history)

Sets the number of last frames that affect the background model.

◆ setNMixtures()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setNMixtures ( int nmixtures)

Sets the number of gaussian components in the background model.

The model needs to be reinitalized to reserve memory.

◆ setShadowThreshold()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setShadowThreshold ( double threshold)

Sets the shadow threshold.

◆ setShadowValue()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setShadowValue ( int value)

Sets the shadow value.

◆ setVarInit()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setVarInit ( double varInit)

Sets the initial variance of each gaussian component.

◆ setVarMax()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setVarMax ( double varMax)

◆ setVarMin()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setVarMin ( double varMin)

◆ setVarThreshold()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setVarThreshold ( double varThreshold)

Sets the variance threshold for the pixel-model match.

◆ setVarThresholdGen()

void OpenCVForUnity.VideoModule.BackgroundSubtractorMOG2.setVarThresholdGen ( double varThresholdGen)

Sets the variance threshold for the pixel-model match used for new mixture component generation.


The documentation for this class was generated from the following file: