Class cv::BackgroundSubtractorMOG2#

Gaussian Mixture-based Background/Foreground Segmentation Algorithm. View details

Collaboration diagram for cv::BackgroundSubtractorMOG2:

Public Member Functions#

Public Member Functions inherited from cv::BackgroundSubtractor
Public Member Functions inherited from cv::Algorithm

Return

Name

Description

Algorithm()

~Algorithm()

void

clear()

Clears the algorithm state.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

String

getDefaultName()

void

read(const FileNode & fn)

Reads algorithm parameters from a file storage.

void

save(const String & filename)

void

write(
    const Ptr< FileStorage > & fs,
    const String & name = String() )

void

write(FileStorage & fs)

Stores algorithm parameters in a file storage.

void

write(
    FileStorage & fs,
    const String & name )

Static Public Member Functions#

Static Public Member Functions inherited from cv::Algorithm

Return

Name

Description

static Ptr< _Tp >

load(
    const String & filename,
    const String & objname = String() )

Loads algorithm from the file.

static Ptr< _Tp >

loadFromString(
    const String & strModel,
    const String & objname = String() )

Loads algorithm from a String.

static Ptr< _Tp >

read(const FileNode & fn)

Reads algorithm from the file node.

Additional Inherited Members#

Protected Member Functions inherited from cv::Algorithm

Return

Name

Description

void

writeFormat(FileStorage & fs)

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#

apply()#

void cv::BackgroundSubtractorMOG2::apply(
InputArray image,
InputArray knownForegroundMask,
OutputArray fgmask,
double learningRate = -1 )

Python:

cv.BackgroundSubtractorMOG2.apply(image[, fgmask[, learningRate]]) -> fgmask
cv.BackgroundSubtractorMOG2.apply(image, knownForegroundMask[, fgmask[, learningRate]]) -> fgmask

Computes a foreground mask and skips known foreground in evaluation.

Parameters

  • image — Next video frame. Floating point frame will be used without scaling and should be in range \([0,255]\).

  • fgmask — The output foreground mask as an 8-bit binary image.

  • knownForegroundMask — The mask for inputting already known foreground, allows model to ignore pixels.

  • learningRate — The 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.

apply()#

void cv::BackgroundSubtractorMOG2::apply(
InputArray image,
OutputArray fgmask,
double learningRate = -1 )

Python:

cv.BackgroundSubtractorMOG2.apply(image[, fgmask[, learningRate]]) -> fgmask
cv.BackgroundSubtractorMOG2.apply(image, knownForegroundMask[, fgmask[, learningRate]]) -> fgmask

Computes a foreground mask.

Parameters

  • image — Next video frame. Floating point frame will be used without scaling and should be in range \([0,255]\).

  • fgmask — The output foreground mask as an 8-bit binary image.

  • learningRate — The 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.

getBackgroundRatio()#

double cv::BackgroundSubtractorMOG2::getBackgroundRatio()

Python:

cv.BackgroundSubtractorMOG2.getBackgroundRatio() -> retval

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 cv::BackgroundSubtractorMOG2::getComplexityReductionThreshold()

Python:

cv.BackgroundSubtractorMOG2.getComplexityReductionThreshold() -> retval

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 cv::BackgroundSubtractorMOG2::getDetectShadows()

Python:

cv.BackgroundSubtractorMOG2.getDetectShadows() -> retval

Returns the shadow detection flag.

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

getHistory()#

int cv::BackgroundSubtractorMOG2::getHistory()

Python:

cv.BackgroundSubtractorMOG2.getHistory() -> retval

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

getNMixtures()#

int cv::BackgroundSubtractorMOG2::getNMixtures()

Python:

cv.BackgroundSubtractorMOG2.getNMixtures() -> retval

Returns the number of gaussian components in the background model.

getShadowThreshold()#

double cv::BackgroundSubtractorMOG2::getShadowThreshold()

Python:

cv.BackgroundSubtractorMOG2.getShadowThreshold() -> retval

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 cv::BackgroundSubtractorMOG2::getShadowValue()

Python:

cv.BackgroundSubtractorMOG2.getShadowValue() -> retval

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 cv::BackgroundSubtractorMOG2::getVarInit()

Python:

cv.BackgroundSubtractorMOG2.getVarInit() -> retval

Returns the initial variance of each gaussian component.

getVarMax()#

double cv::BackgroundSubtractorMOG2::getVarMax()

Python:

cv.BackgroundSubtractorMOG2.getVarMax() -> retval

getVarMin()#

double cv::BackgroundSubtractorMOG2::getVarMin()

Python:

cv.BackgroundSubtractorMOG2.getVarMin() -> retval

getVarThreshold()#

double cv::BackgroundSubtractorMOG2::getVarThreshold()

Python:

cv.BackgroundSubtractorMOG2.getVarThreshold() -> retval

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 cv::BackgroundSubtractorMOG2::getVarThresholdGen()

Python:

cv.BackgroundSubtractorMOG2.getVarThresholdGen() -> retval

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 cv::BackgroundSubtractorMOG2::setBackgroundRatio(double ratio)

Python:

cv.BackgroundSubtractorMOG2.setBackgroundRatio(ratio)

Sets the “background ratio” parameter of the algorithm.

setComplexityReductionThreshold()#

void cv::BackgroundSubtractorMOG2::setComplexityReductionThreshold(double ct)

Python:

cv.BackgroundSubtractorMOG2.setComplexityReductionThreshold(ct)

Sets the complexity reduction threshold.

setDetectShadows()#

void cv::BackgroundSubtractorMOG2::setDetectShadows(bool detectShadows)

Python:

cv.BackgroundSubtractorMOG2.setDetectShadows(detectShadows)

Enables or disables shadow detection.

setHistory()#

void cv::BackgroundSubtractorMOG2::setHistory(int history)

Python:

cv.BackgroundSubtractorMOG2.setHistory(history)

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

setNMixtures()#

void cv::BackgroundSubtractorMOG2::setNMixtures(int nmixtures)

Python:

cv.BackgroundSubtractorMOG2.setNMixtures(nmixtures)

Sets the number of gaussian components in the background model.

The model needs to be reinitialized to reserve memory.

setShadowThreshold()#

void cv::BackgroundSubtractorMOG2::setShadowThreshold(double threshold)

Python:

cv.BackgroundSubtractorMOG2.setShadowThreshold(threshold)

Sets the shadow threshold.

setShadowValue()#

void cv::BackgroundSubtractorMOG2::setShadowValue(int value)

Python:

cv.BackgroundSubtractorMOG2.setShadowValue(value)

Sets the shadow value.

setVarInit()#

void cv::BackgroundSubtractorMOG2::setVarInit(double varInit)

Python:

cv.BackgroundSubtractorMOG2.setVarInit(varInit)

Sets the initial variance of each gaussian component.

setVarMax()#

void cv::BackgroundSubtractorMOG2::setVarMax(double varMax)

Python:

cv.BackgroundSubtractorMOG2.setVarMax(varMax)

setVarMin()#

void cv::BackgroundSubtractorMOG2::setVarMin(double varMin)

Python:

cv.BackgroundSubtractorMOG2.setVarMin(varMin)

setVarThreshold()#

void cv::BackgroundSubtractorMOG2::setVarThreshold(double varThreshold)

Python:

cv.BackgroundSubtractorMOG2.setVarThreshold(varThreshold)

Sets the variance threshold for the pixel-model match.

setVarThresholdGen()#

void cv::BackgroundSubtractorMOG2::setVarThresholdGen(double varThresholdGen)

Python:

cv.BackgroundSubtractorMOG2.setVarThresholdGen(varThresholdGen)

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

Source file#

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