Class 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

    Fields inherited from class org.opencv.core.Algorithm

    nativeObj
  • 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 model
    int getNMixtures()
    Returns the number of gaussian components in the background model
    double 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 component
    double 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 algorithm
    void setComplexityReductionThreshold​(double ct)
    Sets the complexity reduction threshold
    void setDetectShadows​(boolean 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

    Methods inherited from class org.opencv.video.BackgroundSubtractor

    getBackgroundImage

    Methods inherited from class org.opencv.core.Algorithm

    clear, empty, getDefaultName, getNativeObjAddr, save

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • __fromPtr__

      public static BackgroundSubtractorMOG2 __fromPtr__​(long addr)
    • getHistory

      public int getHistory()
      Returns the number of last frames that affect the background model
      Returns:
      automatically generated
    • setHistory

      public void setHistory​(int history)
      Sets the number of last frames that affect the background model
      Parameters:
      history - automatically generated
    • getNMixtures

      public int getNMixtures()
      Returns the number of gaussian components in the background model
      Returns:
      automatically generated
    • setNMixtures

      public 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
    • getBackgroundRatio

      public 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
    • setBackgroundRatio

      public void setBackgroundRatio​(double ratio)
      Sets the "background ratio" parameter of the algorithm
      Parameters:
      ratio - automatically generated
    • getVarThreshold

      public 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
    • setVarThreshold

      public void setVarThreshold​(double varThreshold)
      Sets the variance threshold for the pixel-model match
      Parameters:
      varThreshold - automatically generated
    • getVarThresholdGen

      public 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
    • setVarThresholdGen

      public void setVarThresholdGen​(double varThresholdGen)
      Sets the variance threshold for the pixel-model match used for new mixture component generation
      Parameters:
      varThresholdGen - automatically generated
    • getVarInit

      public double getVarInit()
      Returns the initial variance of each gaussian component
      Returns:
      automatically generated
    • setVarInit

      public void setVarInit​(double varInit)
      Sets the initial variance of each gaussian component
      Parameters:
      varInit - automatically generated
    • getVarMin

      public double getVarMin()
    • setVarMin

      public void setVarMin​(double varMin)
    • getVarMax

      public double getVarMax()
    • setVarMax

      public void setVarMax​(double varMax)
    • 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

      public void setComplexityReductionThreshold​(double ct)
      Sets the complexity reduction threshold
      Parameters:
      ct - automatically generated
    • getDetectShadows

      public boolean getDetectShadows()
      Returns the shadow detection flag If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorMOG2 for details.
      Returns:
      automatically generated
    • setDetectShadows

      public void setDetectShadows​(boolean detectShadows)
      Enables or disables shadow detection
      Parameters:
      detectShadows - automatically generated
    • getShadowValue

      public 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
    • setShadowValue

      public void setShadowValue​(int value)
      Sets the shadow value
      Parameters:
      value - automatically generated
    • getShadowThreshold

      public 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
    • setShadowThreshold

      public void setShadowThreshold​(double threshold)
      Sets the shadow threshold
      Parameters:
      threshold - automatically generated
    • apply

      public void apply​(Mat image, Mat fgmask, double learningRate)
      Computes a foreground mask.
      Overrides:
      apply in 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.
    • apply

      public void apply​(Mat image, Mat fgmask)
      Computes a foreground mask.
      Overrides:
      apply in 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.
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class BackgroundSubtractor
      Throws:
      Throwable