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
Methodand the currentHistory/VarThresholdsettings.If settings changed, the internal background model is reinitialized to reflect the new parameters.
Processes the incoming
Input Imageand produces theForeground Maskshowing 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
HistoryandVarThresholdsliders to balance adaptation speed vs. stability.Produces a ready-to-use foreground mask that can be piped into detection or analysis blocks.
π Usage
Connect an image-producing block (camera, video, or load image) into
Input Image.Select desired
Methodand tuneHistoryandVarThresholdwhile observing results.Use the
Foreground Maskwith downstream blocks for detection, counting, or logging.
π‘ Tips and Tricks
For noisy results, try smoothing the input first with
Bluror reduce high-frequency noise usingDenoisingbefore feeding the image to this block.To remove small speckles from the mask, attach
Morphological Transformationsafter this block to apply opening/closing operations.If you only care about a specific area, crop the input with
Image ROI SelectorImage ROIbefore background subtraction to speed up processing.Use
Show Imageto preview theForeground Maskin a larger viewer for parameter tuning.For object-level analysis, feed the mask into
Blob Detectoror useFind Contourto extract and measure detected components.To annotate or highlight detections on the original frame, combine with
Draw DetectionsorDraw Rectangleusing coordinates derived from contour/blob analysis.If your input frames are very large, insert
Image Resizerto downscale first for faster processing.Persist important frames or masks using
Image LoggerorImage Writewhen a trigger condition occurs (e.g., detection count exceeds a threshold).Use
Image Memoryto 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
VarThresholdor increaseHistoryso the model adapts slower.If moving objects are not detected reliably, decrease
VarThresholdor reduce prior smoothing.If the mask contains small isolated noise, add
Morphological Transformations(opening) or runBluron the input.If the background changes frequently (lighting, moving background), reduce
Historyso the model adapts faster, or restrict processing to a stable ROI withImage ROI Select.If you cannot see the mask clearly, use
Show Imageto open the mask in the image viewer for better inspection.
π Recommended block combinations
Preprocessing:
BlurβBackground SubtractorβMorphological TransformationsFocused detection:
Image ROI SelectβBackground SubtractorβBlob DetectorβDraw DetectionsLogging and review:
Background SubtractorβShow Image(preview) andImage LoggerorImage Write(save masks/frames)Post-analysis:
Background SubtractorβFind Contour/Measure Object DistanceβData to JSONorCSV Export
These combinations help build reliable video-analysis pipelines using the available blocks.
Last updated
Was this helpful?