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 .
- 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedBackgroundSubtractorMOG2(long addr)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods 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 generation- 
Methods inherited from class org.opencv.video.BackgroundSubtractorgetBackgroundImage
 - 
Methods inherited from class org.opencv.core.Algorithmclear, empty, getDefaultName, getNativeObjAddr, save
 
- 
 
- 
- 
- 
Method Detail- 
__fromPtr__public static BackgroundSubtractorMOG2 __fromPtr__(long addr) 
 - 
getHistorypublic int getHistory() Returns the number of last frames that affect the background model- Returns:
- automatically generated
 
 - 
setHistorypublic void setHistory(int history) Sets the number of last frames that affect the background model- Parameters:
- history- automatically generated
 
 - 
getNMixturespublic int getNMixtures() Returns the number of gaussian components in the background model- Returns:
- automatically generated
 
 - 
setNMixturespublic void setNMixtures(int nmixtures) Sets the number of gaussian components in the background model. The model needs to be reinitalized to reserve memory.- Parameters:
- nmixtures- automatically generated
 
 - 
getBackgroundRatiopublic double 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
 
 - 
setBackgroundRatiopublic void setBackgroundRatio(double ratio) Sets the "background ratio" parameter of the algorithm- Parameters:
- ratio- automatically generated
 
 - 
getVarThresholdpublic double 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
 
 - 
setVarThresholdpublic void setVarThreshold(double varThreshold) Sets the variance threshold for the pixel-model match- Parameters:
- varThreshold- automatically generated
 
 - 
getVarThresholdGenpublic double 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
 
 - 
setVarThresholdGenpublic void setVarThresholdGen(double varThresholdGen) Sets the variance threshold for the pixel-model match used for new mixture component generation- Parameters:
- varThresholdGen- automatically generated
 
 - 
getVarInitpublic double getVarInit() Returns the initial variance of each gaussian component- Returns:
- automatically generated
 
 - 
setVarInitpublic void setVarInit(double varInit) Sets the initial variance of each gaussian component- Parameters:
- varInit- automatically generated
 
 - 
getVarMinpublic double getVarMin() 
 - 
setVarMinpublic void setVarMin(double varMin) 
 - 
getVarMaxpublic double getVarMax() 
 - 
setVarMaxpublic void setVarMax(double varMax) 
 - 
getComplexityReductionThresholdpublic double 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
 
 - 
setComplexityReductionThresholdpublic void setComplexityReductionThreshold(double ct) Sets the complexity reduction threshold- Parameters:
- ct- automatically generated
 
 - 
getDetectShadowspublic boolean getDetectShadows() Returns the shadow detection flag If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorMOG2 for details.- Returns:
- automatically generated
 
 - 
setDetectShadowspublic void setDetectShadows(boolean detectShadows) Enables or disables shadow detection- Parameters:
- detectShadows- automatically generated
 
 - 
getShadowValuepublic int 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
 
 - 
setShadowValuepublic void setShadowValue(int value) Sets the shadow value- Parameters:
- value- automatically generated
 
 - 
getShadowThresholdpublic double 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
 
 - 
setShadowThresholdpublic void setShadowThreshold(double threshold) Sets the shadow threshold- Parameters:
- threshold- automatically generated
 
 - 
applypublic void apply(Mat image, Mat fgmask, double learningRate) Computes a foreground mask.- Overrides:
- applyin class- BackgroundSubtractor
- 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.
 
 - 
applypublic void apply(Mat image, Mat fgmask) Computes a foreground mask.- Overrides:
- applyin class- BackgroundSubtractor
- 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.
 
 - 
finalizeprotected void finalize() throws java.lang.Throwable- Overrides:
- finalizein class- BackgroundSubtractor
- Throws:
- java.lang.Throwable
 
 
- 
 
-