vpi.BackgroundSubtractor.__call__

BackgroundSubtractor.__call__(input: vpi.Image, *, out_fgmask: vpi.Image = None, out_bg: vpi.Image = None, threshold: float = 16.0, shadow: Optional[int] = 127, learnrate: float = 0.001, stream: vpi.Stream = None) Tuple[vpi.Image, vpi.Image]
BackgroundSubtractor.__call__(input: vpi.Image, *, threshold: float = 16.0, shadow: Optional[int] = 127, learnrate: float = 0.001, stream: vpi.Stream = None) Tuple[vpi.Image, vpi.Image]

Extracts fore/background of the input image.

The background subtractor (BgSub) algorithm separates foreground and background of the input image. This function runs the BgSub algorithm and extracts either both the foreground mask and the background image or only the foreground mask. To extract only the foreground mask, pass only the out_fgmask argument.

Hint

The input image may be a frame of a video. This function is potentially slower to extract both fore/background than only the foreground. This function is based on the BgSub class.

See also

Refer to the algorithm explanation for more details and usage examples.

Parameters
  • input (vpi.Image) – Input image frame to be processed by the algorithm.

  • out_fgmask (vpi.Image, optional) – The output foreground mask as an 8-bit binary image. The only accepted format is vpi.Format.U8. Pass only this output argument to extract only the foreground mask.

  • out_bg (vpi.Image, optional) – The background image.

  • threshold (float, optional) – Threshold on the squared Mahalanobis distance between the pixel and the model to decide whether a pixel is well described by the background model.

  • shadow (int, optional) – The algorithm will detect shadow if this is non-zero. It sets the pixel value representing shadow.

  • learnrate (float, optional) – Learning rate that indicates how fast the background model is learnt. See C API for details.

  • stream (vpi.Stream, optional) – The stream to be used by the algorithm.

Returns

A tuple with the output foreground mask and background image, respectively.

Return type

Tuple[vpi.Image, vpi.Image]

Caution

Restrictions to several arguments may apply. Check the C API references of the submit function and the group concepts for more details.