# Optical Flow

**Optical Flow** node analyzes the movement of pixels from frame to frame and detects moving parts based on the current and previous frames. This node requires CV Mat input and produces a CV Mat output.

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

**Optical Flow** node analyzes a CV image to identify moving pixels. It compares the current and previous input images to determine these moving parts. The resulting information is stored in the CV output as HSV values. The H channel represents the direction or displacement of the detected movement, while the V channel represents the velocity of the moving part.

## Input pins

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

* **CV input:** input image on which moving parts will be detected.
* **Scales number:** the amount of detail in the moving area. A higher *Scale numbers* value translates into a more detailed Output image.

{% hint style="info" %}
**Good to know:** If computation is slow, you can try lowering *Scales number* value.
{% endhint %}

* **Scales step:** expressed as a ratio. If the object is small and moving fast through the images *Scales number* and *Scales step* parameters can be reduced.
* **Median filter size:** higher number results in more "blurry" rectangular-shaped detected moving areas. If the object is moving fast through the image, the *Median filter size* parameter can be set to a higher number than the default.
* **Threshold magnitude:** if the maximum detected magnitude, or velocity, in the whole image is below this value then the output image will be black.
* **Dynamic magnitude:** If disabled then the magnitude for each pixel will be divided by *Normalize magnitude* parameter and stored in V channel. If this checkbox is Enabled, then the maximum magnitude will be set to 255 and the minimum magnitude will be set to 0 in V channel. All values in between will be linearly interpolated.
* **Dynamic Flow:** If this checkbox is disabled, then only the current and previous images from the incoming video stream will be used in detection. If enabled, however, the optical flow algorithm will also use results from the previous detection.

## Output pins

* **Output: d**etected parts of input images in HSV where H is moving direction and V is moving velocity.
* **Max magnitude:** maximum magnitude, or velocity, of all detected parts in the *Output* image.\
  This value is not normalized as is the *V channel* in the *Output* image.


---

# 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/optical-flow.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.
