# 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="https://3312042618-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVaJpWJhPbmscipukhh%2Fuploads%2Fgit-blob-dad2eb8342ebc74b6da5494e6bf9c5f23ca7def7%2FMog2Subtraction.gif?alt=media" alt=""><figcaption></figcaption></figure>

## Input pins

<div align="left"><figure><img src="https://3312042618-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVaJpWJhPbmscipukhh%2Fuploads%2Fgit-blob-717605646e77141af81e03863b4a7a487e7ed636%2Fmog2subtraction.png?alt=media" 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lightact.com/layers-and-layouts/layer-layouts/nodes/computer-vision/mog2-background-subtraction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
