Background Subtractor

This function block detects moving/foreground regions by comparing current frames against a learned background model. Use it to separate foreground objects (people, vehicles, moving parts) from a stable background and produce a binary/grayscale foreground mask for further analysis.

πŸ“₯ Inputs (sockets)

Input Image Accepts the input image or video frame to be analyzed (color or grayscale).

πŸ“€ Outputs (sockets)

Foreground Mask Outputs a grayscale/binary mask where foreground pixels are highlighted.

πŸ•ΉοΈ Controls

Method Choose the background subtraction algorithm (e.g. MOG2 or KNN) available in the dropdown.

History Controls how many past frames are used to build the background model. Higher values make the model adapt slower.

VarThreshold Controls sensitivity to pixel changes. Lower values make the subtractor more sensitive to small changes; higher values make it less sensitive.

βš™οΈ Running mechanism

Each time the block runs it:

  • Uses the selected Method and the current History / VarThreshold settings.

  • If settings changed, the internal background model is reinitialized to reflect the new parameters.

  • Processes the incoming Input Image and produces the Foreground Mask showing detected foreground regions.

This mask is updated frame-by-frame and can be consumed by other blocks for counting, tracking, or saving.

🎯 Features

  • Quick switching between algorithms using Method.

  • Real-time parameter tuning with History and VarThreshold sliders to balance adaptation speed vs. stability.

  • Produces a ready-to-use foreground mask that can be piped into detection or analysis blocks.

πŸ“ Usage

  1. Connect an image-producing block (camera, video, or load image) into Input Image.

  2. Select desired Method and tune History and VarThreshold while observing results.

  3. Use the Foreground Mask with downstream blocks for detection, counting, or logging.

πŸ’‘ Tips and Tricks

  • For noisy results, try smoothing the input first with Blur or reduce high-frequency noise using Denoising before feeding the image to this block.

  • To remove small speckles from the mask, attach Morphological Transformations after this block to apply opening/closing operations.

  • If you only care about a specific area, crop the input with Image ROI Select or Image ROI before background subtraction to speed up processing.

  • Use Show Image to preview the Foreground Mask in a larger viewer for parameter tuning.

  • For object-level analysis, feed the mask into Blob Detector or use Find Contour to extract and measure detected components.

  • To annotate or highlight detections on the original frame, combine with Draw Detections or Draw Rectangle using coordinates derived from contour/blob analysis.

  • If your input frames are very large, insert Image Resizer to downscale first for faster processing.

  • Persist important frames or masks using Image Logger or Image Write when a trigger condition occurs (e.g., detection count exceeds a threshold).

  • Use Image Memory to freeze a frame for inspection while live processing continues.

(hints above reference only the available function blocks list)

πŸ› οΈ Troubleshooting

  • If the foreground mask is too sensitive (many flickering pixels), increase VarThreshold or increase History so the model adapts slower.

  • If moving objects are not detected reliably, decrease VarThreshold or reduce prior smoothing.

  • If the mask contains small isolated noise, add Morphological Transformations (opening) or run Blur on the input.

  • If the background changes frequently (lighting, moving background), reduce History so the model adapts faster, or restrict processing to a stable ROI with Image ROI Select.

  • If you cannot see the mask clearly, use Show Image to open the mask in the image viewer for better inspection.

  • Preprocessing: Blur β†’ Background Subtractor β†’ Morphological Transformations

  • Focused detection: Image ROI Select β†’ Background Subtractor β†’ Blob Detector β†’ Draw Detections

  • Logging and review: Background Subtractor β†’ Show Image (preview) and Image Logger or Image Write (save masks/frames)

  • Post-analysis: Background Subtractor β†’ Find Contour / Measure Object Distance β†’ Data to JSON or CSV Export

These combinations help build reliable video-analysis pipelines using the available blocks.

Last updated

Was this helpful?