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 protected
BackgroundSubtractorMOG2(long addr)
-
Method Summary
Modifier and Type Method Description static BackgroundSubtractorMOG2
__fromPtr__(long addr)
void
apply(Mat image, Mat fgmask)
Computes a foreground mask.void
apply(Mat image, Mat fgmask, double learningRate)
Computes a foreground mask.protected void
finalize()
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.double
getComplexityReductionThreshold()
Returns the complexity reduction threshold This parameter defines the number of samples needed to accept to prove the component exists.boolean
getDetectShadows()
Returns the shadow detection flag If true, the algorithm detects shadows and marks them.int
getHistory()
Returns the number of last frames that affect the background modelint
getNMixtures()
Returns the number of gaussian components in the background modeldouble
getShadowThreshold()
Returns the shadow threshold A shadow is detected if pixel is a darker version of the background.int
getShadowValue()
Returns the shadow value Shadow value is the value used to mark shadows in the foreground mask.double
getVarInit()
Returns the initial variance of each gaussian componentdouble
getVarMax()
double
getVarMin()
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.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).void
setBackgroundRatio(double ratio)
Sets the "background ratio" parameter of the algorithmvoid
setComplexityReductionThreshold(double ct)
Sets the complexity reduction thresholdvoid
setDetectShadows(boolean detectShadows)
Enables or disables shadow detectionvoid
setHistory(int history)
Sets the number of last frames that affect the background modelvoid
setNMixtures(int nmixtures)
Sets the number of gaussian components in the background model.void
setShadowThreshold(double threshold)
Sets the shadow thresholdvoid
setShadowValue(int value)
Sets the shadow valuevoid
setVarInit(double varInit)
Sets the initial variance of each gaussian componentvoid
setVarMax(double varMax)
void
setVarMin(double varMin)
void
setVarThreshold(double varThreshold)
Sets the variance threshold for the pixel-model matchvoid
setVarThresholdGen(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:
apply
in 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:
apply
in 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:
finalize
in classBackgroundSubtractor
- Throws:
Throwable
-