View Source Evision.BackgroundSubtractorMOG2 (Evision v0.2.9)

Summary

Types

t()

Type that represents an BackgroundSubtractorMOG2 struct.

Functions

Computes a foreground mask.

Computes a foreground mask.

Clears the algorithm state

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

Computes a background image.

Computes a background image.

Returns the "background ratio" parameter of the algorithm

Returns the complexity reduction threshold

Returns the shadow detection flag

Returns the number of last frames that affect the background model

Returns the number of gaussian components in the background model

Returns the shadow threshold

Returns the shadow value

Returns the initial variance of each gaussian component

Returns the variance threshold for the pixel-model match

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

Reads algorithm parameters from a file storage

Sets the "background ratio" parameter of the algorithm

Sets the complexity reduction threshold

Enables or disables shadow detection

Sets the number of last frames that affect the background model

Sets the number of gaussian components in the background model.

Sets the shadow threshold

Sets the shadow value

Sets the initial variance of each gaussian component

Sets the variance threshold for the pixel-model match

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

Stores algorithm parameters in a file storage

Types

@type t() :: %Evision.BackgroundSubtractorMOG2{ref: reference()}

Type that represents an BackgroundSubtractorMOG2 struct.

  • ref. reference()

    The underlying erlang resource variable.

Functions

@spec apply(Keyword.t()) :: any() | {:error, String.t()}
@spec apply(t(), Evision.Mat.maybe_mat_in()) :: Evision.Mat.t() | {:error, String.t()}

Computes a foreground mask.

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()

  • image: Evision.Mat.

    Next video frame. Floating point frame will be used without scaling and should be in range \f$[0,255]\f$.

Keyword Arguments
  • learningRate: double.

    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.

Return
  • fgmask: Evision.Mat.t().

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

Python prototype (for reference only):

apply(image[, fgmask[, learningRate]]) -> fgmask
Link to this function

apply(self, image, opts)

View Source
@spec apply(t(), Evision.Mat.maybe_mat_in(), [{:learningRate, term()}] | nil) ::
  Evision.Mat.t() | {:error, String.t()}

Computes a foreground mask.

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()

  • image: Evision.Mat.

    Next video frame. Floating point frame will be used without scaling and should be in range \f$[0,255]\f$.

Keyword Arguments
  • learningRate: double.

    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.

Return
  • fgmask: Evision.Mat.t().

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

Python prototype (for reference only):

apply(image[, fgmask[, learningRate]]) -> fgmask
@spec clear(Keyword.t()) :: any() | {:error, String.t()}
@spec clear(t()) :: t() | {:error, String.t()}

Clears the algorithm state

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()

Python prototype (for reference only):

clear() -> None
@spec empty(Keyword.t()) :: any() | {:error, String.t()}
@spec empty(t()) :: boolean() | {:error, String.t()}

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

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: bool

Python prototype (for reference only):

empty() -> retval
Link to this function

getBackgroundImage(named_args)

View Source
@spec getBackgroundImage(Keyword.t()) :: any() | {:error, String.t()}
@spec getBackgroundImage(t()) :: Evision.Mat.t() | {:error, String.t()}

Computes a background image.

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • backgroundImage: Evision.Mat.t().

    The output background image.

Note: Sometimes the background image can be very blurry, as it contain the average background statistics.

Python prototype (for reference only):

getBackgroundImage([, backgroundImage]) -> backgroundImage
Link to this function

getBackgroundImage(self, opts)

View Source
@spec getBackgroundImage(t(), [{atom(), term()}, ...] | nil) ::
  Evision.Mat.t() | {:error, String.t()}

Computes a background image.

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • backgroundImage: Evision.Mat.t().

    The output background image.

Note: Sometimes the background image can be very blurry, as it contain the average background statistics.

Python prototype (for reference only):

getBackgroundImage([, backgroundImage]) -> backgroundImage
Link to this function

getBackgroundRatio(named_args)

View Source
@spec getBackgroundRatio(Keyword.t()) :: any() | {:error, String.t()}
@spec getBackgroundRatio(t()) :: number() | {:error, String.t()}

Returns the "background ratio" parameter of the algorithm

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

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.

Python prototype (for reference only):

getBackgroundRatio() -> retval
Link to this function

getComplexityReductionThreshold(named_args)

View Source
@spec getComplexityReductionThreshold(Keyword.t()) :: any() | {:error, String.t()}
@spec getComplexityReductionThreshold(t()) :: number() | {:error, String.t()}

Returns the complexity reduction threshold

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

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.

Python prototype (for reference only):

getComplexityReductionThreshold() -> retval
Link to this function

getDefaultName(named_args)

View Source
@spec getDefaultName(Keyword.t()) :: any() | {:error, String.t()}
@spec getDefaultName(t()) :: binary() | {:error, String.t()}

getDefaultName

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return

Returns the algorithm string identifier. This string is used as top level xml/yml node tag when the object is saved to a file or string.

Python prototype (for reference only):

getDefaultName() -> retval
Link to this function

getDetectShadows(named_args)

View Source
@spec getDetectShadows(Keyword.t()) :: any() | {:error, String.t()}
@spec getDetectShadows(t()) :: boolean() | {:error, String.t()}

Returns the shadow detection flag

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: bool

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

Python prototype (for reference only):

getDetectShadows() -> retval
@spec getHistory(Keyword.t()) :: any() | {:error, String.t()}
@spec getHistory(t()) :: integer() | {:error, String.t()}

Returns the number of last frames that affect the background model

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: integer()

Python prototype (for reference only):

getHistory() -> retval
Link to this function

getNMixtures(named_args)

View Source
@spec getNMixtures(Keyword.t()) :: any() | {:error, String.t()}
@spec getNMixtures(t()) :: integer() | {:error, String.t()}

Returns the number of gaussian components in the background model

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: integer()

Python prototype (for reference only):

getNMixtures() -> retval
Link to this function

getShadowThreshold(named_args)

View Source
@spec getShadowThreshold(Keyword.t()) :: any() | {:error, String.t()}
@spec getShadowThreshold(t()) :: number() | {:error, String.t()}

Returns the shadow threshold

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

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.

Python prototype (for reference only):

getShadowThreshold() -> retval
Link to this function

getShadowValue(named_args)

View Source
@spec getShadowValue(Keyword.t()) :: any() | {:error, String.t()}
@spec getShadowValue(t()) :: integer() | {:error, String.t()}

Returns the shadow value

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: integer()

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.

Python prototype (for reference only):

getShadowValue() -> retval
@spec getVarInit(Keyword.t()) :: any() | {:error, String.t()}
@spec getVarInit(t()) :: number() | {:error, String.t()}

Returns the initial variance of each gaussian component

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

Python prototype (for reference only):

getVarInit() -> retval
@spec getVarMax(Keyword.t()) :: any() | {:error, String.t()}
@spec getVarMax(t()) :: number() | {:error, String.t()}

getVarMax

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

Python prototype (for reference only):

getVarMax() -> retval
@spec getVarMin(Keyword.t()) :: any() | {:error, String.t()}
@spec getVarMin(t()) :: number() | {:error, String.t()}

getVarMin

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

Python prototype (for reference only):

getVarMin() -> retval
Link to this function

getVarThreshold(named_args)

View Source
@spec getVarThreshold(Keyword.t()) :: any() | {:error, String.t()}
@spec getVarThreshold(t()) :: number() | {:error, String.t()}

Returns the variance threshold for the pixel-model match

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

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.

Python prototype (for reference only):

getVarThreshold() -> retval
Link to this function

getVarThresholdGen(named_args)

View Source
@spec getVarThresholdGen(Keyword.t()) :: any() | {:error, String.t()}
@spec getVarThresholdGen(t()) :: number() | {:error, String.t()}

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

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
Return
  • retval: double

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.

Python prototype (for reference only):

getVarThresholdGen() -> retval
@spec read(Keyword.t()) :: any() | {:error, String.t()}
@spec read(t(), Evision.FileNode.t()) :: t() | {:error, String.t()}

Reads algorithm parameters from a file storage

Positional Arguments

Python prototype (for reference only):

read(fn) -> None
@spec save(Keyword.t()) :: any() | {:error, String.t()}
@spec save(t(), binary()) :: t() | {:error, String.t()}

save

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • filename: String

Saves the algorithm to a file. In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs).

Python prototype (for reference only):

save(filename) -> None
Link to this function

setBackgroundRatio(named_args)

View Source
@spec setBackgroundRatio(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setBackgroundRatio(self, ratio)

View Source
@spec setBackgroundRatio(t(), number()) :: t() | {:error, String.t()}

Sets the "background ratio" parameter of the algorithm

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • ratio: double

Python prototype (for reference only):

setBackgroundRatio(ratio) -> None
Link to this function

setComplexityReductionThreshold(named_args)

View Source
@spec setComplexityReductionThreshold(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setComplexityReductionThreshold(self, ct)

View Source
@spec setComplexityReductionThreshold(t(), number()) :: t() | {:error, String.t()}

Sets the complexity reduction threshold

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • ct: double

Python prototype (for reference only):

setComplexityReductionThreshold(ct) -> None
Link to this function

setDetectShadows(named_args)

View Source
@spec setDetectShadows(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setDetectShadows(self, detectShadows)

View Source
@spec setDetectShadows(t(), boolean()) :: t() | {:error, String.t()}

Enables or disables shadow detection

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • detectShadows: bool

Python prototype (for reference only):

setDetectShadows(detectShadows) -> None
@spec setHistory(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setHistory(self, history)

View Source
@spec setHistory(t(), integer()) :: t() | {:error, String.t()}

Sets the number of last frames that affect the background model

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • history: integer()

Python prototype (for reference only):

setHistory(history) -> None
Link to this function

setNMixtures(named_args)

View Source
@spec setNMixtures(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setNMixtures(self, nmixtures)

View Source
@spec setNMixtures(t(), integer()) :: t() | {:error, String.t()}

Sets the number of gaussian components in the background model.

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • nmixtures: integer()

The model needs to be reinitalized to reserve memory.

Python prototype (for reference only):

setNMixtures(nmixtures) -> None
Link to this function

setShadowThreshold(named_args)

View Source
@spec setShadowThreshold(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setShadowThreshold(self, threshold)

View Source
@spec setShadowThreshold(t(), number()) :: t() | {:error, String.t()}

Sets the shadow threshold

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • threshold: double

Python prototype (for reference only):

setShadowThreshold(threshold) -> None
Link to this function

setShadowValue(named_args)

View Source
@spec setShadowValue(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setShadowValue(self, value)

View Source
@spec setShadowValue(t(), integer()) :: t() | {:error, String.t()}

Sets the shadow value

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • value: integer()

Python prototype (for reference only):

setShadowValue(value) -> None
@spec setVarInit(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setVarInit(self, varInit)

View Source
@spec setVarInit(t(), number()) :: t() | {:error, String.t()}

Sets the initial variance of each gaussian component

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • varInit: double

Python prototype (for reference only):

setVarInit(varInit) -> None
@spec setVarMax(Keyword.t()) :: any() | {:error, String.t()}
@spec setVarMax(t(), number()) :: t() | {:error, String.t()}

setVarMax

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • varMax: double

Python prototype (for reference only):

setVarMax(varMax) -> None
@spec setVarMin(Keyword.t()) :: any() | {:error, String.t()}
@spec setVarMin(t(), number()) :: t() | {:error, String.t()}

setVarMin

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • varMin: double

Python prototype (for reference only):

setVarMin(varMin) -> None
Link to this function

setVarThreshold(named_args)

View Source
@spec setVarThreshold(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setVarThreshold(self, varThreshold)

View Source
@spec setVarThreshold(t(), number()) :: t() | {:error, String.t()}

Sets the variance threshold for the pixel-model match

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • varThreshold: double

Python prototype (for reference only):

setVarThreshold(varThreshold) -> None
Link to this function

setVarThresholdGen(named_args)

View Source
@spec setVarThresholdGen(Keyword.t()) :: any() | {:error, String.t()}
Link to this function

setVarThresholdGen(self, varThresholdGen)

View Source
@spec setVarThresholdGen(t(), number()) :: t() | {:error, String.t()}

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

Positional Arguments
  • self: Evision.BackgroundSubtractorMOG2.t()
  • varThresholdGen: double

Python prototype (for reference only):

setVarThresholdGen(varThresholdGen) -> None
@spec write(Keyword.t()) :: any() | {:error, String.t()}
@spec write(t(), Evision.FileStorage.t()) :: t() | {:error, String.t()}

Stores algorithm parameters in a file storage

Positional Arguments

Python prototype (for reference only):

write(fs) -> None
@spec write(t(), Evision.FileStorage.t(), binary()) :: t() | {:error, String.t()}

write

Positional Arguments

Has overloading in C++

Python prototype (for reference only):

write(fs, name) -> None