> For the complete documentation index, see [llms.txt](https://docs.lightact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lightact.com/layers-and-layouts/layer-layouts/nodes/computer-vision/mog2-background-subtraction.md).

# Mog2 Background Subtraction

**Mog2 Background Subtraction** node separates the foreground from the background in a video stream. It does so by subtracting the background image from the current frame to reveal the foreground objects.

<figure><img src="/files/iubmKdxf02LjpRIOwI8y" alt=""><figcaption></figcaption></figure>

## Input pins

<div align="left"><figure><img src="/files/2N89dlYgEyyJIDy7sZXS" alt=""><figcaption></figcaption></figure></div>

* **Input:** incoming CV Mat with 1, 3, or 4 channels,
* **History:** number of frames used to produce background image.
* **Learn rate:** if smaller than 0, then the value is ignored and the best *Learn rate* is chosen automatically. If the value is equal to 0 or larger than 1, the background image will not be updated with the Input image. If it is 1, the background image will always update with the last Input.
* **Threshold variance:** variance parameter MOG2 background subtraction,
* **Detect Shadows:** detects shadows in the incoming stream. If a shadow is detected, then it will be represented with grey color in the output.

## Output pins

* **Output:** outgoing CV Mat stream in which foreground objects are represented in white, background objects are in black color, and shadows, if present, are displayed with grey color.
* **Background:** background image from which the current frame is subtracted.
