Package org.opencv.video
Class BackgroundSubtractorMOG2
java.lang.Object
org.opencv.core.Algorithm
org.opencv.video.BackgroundSubtractor
org.opencv.video.BackgroundSubtractorMOG2
public class BackgroundSubtractorMOG2 extends BackgroundSubtractor
Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
The class implements the Gaussian mixture model background subtraction described in CITE: Zivkovic2004
and CITE: Zivkovic2006 .
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedBackgroundSubtractorMOG2(long addr) -
Method Summary
Modifier and Type Method Description static BackgroundSubtractorMOG2__fromPtr__(long addr)voidapply(Mat image, Mat fgmask)Computes a foreground mask.voidapply(Mat image, Mat fgmask, double learningRate)Computes a foreground mask.protected voidfinalize()doublegetBackgroundRatio()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.doublegetComplexityReductionThreshold()Returns the complexity reduction threshold This parameter defines the number of samples needed to accept to prove the component exists.booleangetDetectShadows()Returns the shadow detection flag If true, the algorithm detects shadows and marks them.intgetHistory()Returns the number of last frames that affect the background modelintgetNMixtures()Returns the number of gaussian components in the background modeldoublegetShadowThreshold()Returns the shadow threshold A shadow is detected if pixel is a darker version of the background.intgetShadowValue()Returns the shadow value Shadow value is the value used to mark shadows in the foreground mask.doublegetVarInit()Returns the initial variance of each gaussian componentdoublegetVarMax()doublegetVarMin()doublegetVarThreshold()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.doublegetVarThresholdGen()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).voidsetBackgroundRatio(double ratio)Sets the "background ratio" parameter of the algorithmvoidsetComplexityReductionThreshold(double ct)Sets the complexity reduction thresholdvoidsetDetectShadows(boolean detectShadows)Enables or disables shadow detectionvoidsetHistory(int history)Sets the number of last frames that affect the background modelvoidsetNMixtures(int nmixtures)Sets the number of gaussian components in the background model.voidsetShadowThreshold(double threshold)Sets the shadow thresholdvoidsetShadowValue(int value)Sets the shadow valuevoidsetVarInit(double varInit)Sets the initial variance of each gaussian componentvoidsetVarMax(double varMax)voidsetVarMin(double varMin)voidsetVarThreshold(double varThreshold)Sets the variance threshold for the pixel-model matchvoidsetVarThresholdGen(double varThresholdGen)Sets the variance threshold for the pixel-model match used for new mixture component generationMethods inherited from class org.opencv.core.Algorithm
clear, empty, getDefaultName, getNativeObjAddr, save
-
Constructor Details
-
Method Details
-
__fromPtr__
-
getHistory
Returns the number of last frames that affect the background model- Returns:
- automatically generated
-
setHistory
Sets the number of last frames that affect the background model- Parameters:
history- automatically generated
-
getNMixtures
Returns the number of gaussian components in the background model- Returns:
- automatically generated
-
setNMixtures
Sets the number of gaussian components in the background model. The model needs to be reinitalized to reserve memory.- Parameters:
nmixtures- automatically generated
-
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.- Returns:
- automatically generated
-
setBackgroundRatio
Sets the "background ratio" parameter of the algorithm- Parameters:
ratio- automatically generated
-
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.- Returns:
- automatically generated
-
setVarThreshold
Sets the variance threshold for the pixel-model match- Parameters:
varThreshold- automatically generated
-
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.- Returns:
- automatically generated
-
setVarThresholdGen
Sets the variance threshold for the pixel-model match used for new mixture component generation- Parameters:
varThresholdGen- automatically generated
-
getVarInit
Returns the initial variance of each gaussian component- Returns:
- automatically generated
-
setVarInit
Sets the initial variance of each gaussian component- Parameters:
varInit- automatically generated
-
getVarMin
-
setVarMin
-
getVarMax
-
setVarMax
-
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.- Returns:
- automatically generated
-
setComplexityReductionThreshold
Sets the complexity reduction threshold- Parameters:
ct- automatically generated
-
getDetectShadows
Returns the shadow detection flag If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorMOG2 for details.- Returns:
- automatically generated
-
setDetectShadows
Enables or disables shadow detection- Parameters:
detectShadows- automatically generated
-
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.- Returns:
- automatically generated
-
setShadowValue
Sets the shadow value- Parameters:
value- automatically generated
-
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.- Returns:
- automatically generated
-
setShadowThreshold
Sets the shadow threshold- Parameters:
threshold- automatically generated
-
apply
Computes a foreground mask.- Overrides:
applyin classBackgroundSubtractor- 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.
-
apply
Computes a foreground mask.- Overrides:
applyin classBackgroundSubtractor- 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. 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.
-
finalize
- Overrides:
finalizein classBackgroundSubtractor- Throws:
Throwable
-