Motion Detection¶
Class: MotionDetectionBlockV1
Source: inference.core.workflows.core_steps.classical_cv.motion_detection.v1.MotionDetectionBlockV1
Detect motion in video streams using OpenCV's background subtraction algorithm.
How This Block Works¶
This block uses background subtraction (specifically the MOG2 algorithm) to detect motion in video frames. The block maintains state across frames to build a background model and track motion patterns:
- Initializes background model - on the first frame, creates a background subtractor using the specified history and threshold parameters
- Processes each frame - applies background subtraction to identify pixels that differ from the learned background model
- Filters noise - applies morphological operations to remove noise and combine nearby motion regions into coherent contours
- Extracts motion regions - finds contours representing motion areas, filters them by minimum size, and optionally clips them to a detection zone
- Simplifies contours - reduces contour complexity to keep detection data manageable
- Generates outputs - creates object detection predictions with bounding boxes, determines motion status, triggers alarms when motion starts, and provides motion zone polygons
The block tracks motion state across frames - the alarm output becomes true only when motion transitions from not detected to detected, making it useful for triggering actions when motion first appears.
Common Use Cases¶
- Security Monitoring: Detect motion in surveillance cameras to trigger alerts, recordings, or notifications when activity is detected
- Resource Optimization: Conditionally run expensive inference operations (e.g., object detection, classification) only when motion is detected to save computational resources
- Activity Detection: Monitor areas for movement to track occupancy, identify entry/exit events, or detect unauthorized access
- Video Analytics: Analyze video streams to identify motion patterns, track activity levels, or detect anomalies in monitored areas
- Smart Recording: Trigger video recording or snapshot capture when motion is detected, reducing storage requirements compared to continuous recording
- Zone Monitoring: Monitor specific areas within a frame using detection zones to focus motion detection on relevant regions while ignoring busy but irrelevant areas
Connecting to Other Blocks¶
The motion detection outputs from this block can be connected to:
- Conditional logic blocks (e.g., Continue If) to execute workflow steps only when motion is detected or when alarms trigger
- Object detection blocks to run detection models only on frames with motion, saving computational resources
- Notification blocks (e.g., Email Notification, Slack Notification) to send alerts when motion is detected or alarms trigger
- Data storage blocks (e.g., Roboflow Dataset Upload, CSV Formatter) to log motion events, timestamps, and detection data for analytics
- Visualization blocks to draw motion zones, bounding boxes, or annotations on frames showing detected motion
- Filter blocks to filter images or data based on motion status before passing to downstream processing
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/motion_detection@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
minimum_contour_area |
int |
Minimum area in square pixels for a motion region to be detected. Contours smaller than this threshold are filtered out to ignore noise, small shadows, or minor pixel variations. Lower values increase sensitivity but may detect more false positives (e.g., 100 for very sensitive detection, 500 for only large objects). Default is 200 square pixels.. | ✅ |
morphological_kernel_size |
int |
Size of the morphological kernel in pixels used to combine nearby motion regions and filter noise. Larger values merge more distant motion regions into single contours but may also merge separate objects. Smaller values preserve more detail but may leave fragmented detections. The kernel uses an elliptical shape. Default is 3 pixels.. | ✅ |
threshold |
int |
Threshold value for the squared Mahalanobis distance used by the MOG2 background subtraction algorithm. Controls sensitivity to motion - smaller values increase sensitivity (detect smaller changes) but may produce more false positives, larger values decrease sensitivity (only detect significant changes) but may miss subtle motion. Recommended range is 8-32. Default is 16.. | ✅ |
history |
int |
Number of previous frames used to build the background model. Controls how quickly the background adapts to changes - larger values (e.g., 50-100) create a more stable background model that's less sensitive to temporary changes but adapts slowly to permanent background changes. Smaller values (e.g., 10-20) allow faster adaptation but may treat moving objects as background if they stop moving. Default is 30 frames.. | ✅ |
detection_zone |
Union[List[Any], str] |
Optional polygon zone to limit motion detection to a specific area of the frame. Motion is only detected within this zone, ignoring activity outside. Format: [[x1, y1], [x2, y2], [x3, y3], ...] where coordinates are in pixels. The polygon must have more than 3 points. Can be provided as a list, JSON string, or selector referencing zone outputs from other blocks. Useful for focusing on specific regions (e.g., doorways, windows, restricted areas) while ignoring busy but irrelevant areas. If not provided, motion is detected across the entire frame.. | ✅ |
suppress_first_detections |
bool |
If true, suppresses motion detections until the background model has been initialized with enough frames (specified by the history parameter). This prevents false positives from early frames where the background model hasn't learned the scene yet. When false, the block attempts to detect motion immediately, which may produce unreliable results during initialization. Default is true (recommended for most use cases).. | ✅ |
The Refs column marks possibility to parametrise the property with dynamic values available
in workflow runtime. See Bindings for more info.
Runtime compatibility¶
-
soft— runtimehosted_serverless,dedicated_deployment; executionremote; inputvideo - Block keeps per-video state in process memory (keyed by video_metadata.video_identifier). With remote step execution on stateless or multi-replica HTTP runtimes, successive requests may be served by different worker processes, so the state resets between calls and the output is meaningless for tracking / counting / aggregation. Use local step execution in an InferencePipeline for stable cross-frame results.
-
soft— inputimage - Block depends on temporal context from video or repeated-frame workflows. With a still image/photo, there is no meaningful history to track, compare, aggregate, or visualize, so the block provides little or no benefit.
Available Connections¶
Compatible Blocks
Check what blocks you can connect to Motion Detection in version v1.
- inputs:
PLC Writer,Image Blur,Stability AI Outpainting,Blur Visualization,Frame Delay,Bounding Box Visualization,Absolute Static Crop,Crop Visualization,Reference Path Visualization,OpenAI,Polygon Visualization,Anthropic Claude,Google Gemini,Roboflow Visual Search Classifier,Roboflow Dataset Upload,VLM As Detector,Event Writer,Image Slicer,Image Convert Grayscale,VLM As Classifier,Email Notification,Webhook Sink,Contrast Enhancement,Template Matching,VLM As Classifier,Perspective Correction,Motion Detection,Clip Comparison,Detections List Roll-Up,Buffer,Halo Visualization,SIFT,Slack Notification,Label Visualization,Dimension Collapse,MoonshotAI Kimi,Dynamic Crop,OpenRouter,PLC Reader,Detections Consensus,Label Visualization,PLC EthernetIP,GeoTag Detection,S3 Sink,Halo Visualization,Line Counter Visualization,Email Notification,Detection Event Log,Roboflow Asset Library Attributes,Pixel Color Count,Background Subtraction,Ellipse Visualization,Stitch Images,Size Measurement,OPC UA Writer Sink,Relative Static Crop,Corner Visualization,Triangle Visualization,Depth Estimation,SIFT Comparison,Qwen-VL,JSON Parser,Distance Measurement,Dot Visualization,Camera Calibration,Google Gemini,Florence-2 Model,Background Color Visualization,Google Gemini,Polygon Zone Visualization,Image Contours,Roboflow Custom Metadata,Roboflow Dataset Upload,Camera Focus,Qwen 3.5 API,MoonshotAI Kimi,Stability AI Inpainting,Contrast Equalization,Morphological Transformation,SIFT Comparison,Image Threshold,Trace Visualization,Color Visualization,Camera Focus,Line Counter,Stability AI Image Generation,Llama 3.2 Vision,Local File Sink,Llama 3.2 Vision,Circle Visualization,QR Code Generator,Morphological Transformation,Dynamic Zone,Google Gemini,Google Gemma API,Model Monitoring Inference Aggregator,Google Gemma,Roboflow Vision Events,Heatmap Visualization,Twilio SMS Notification,Auto Rotate on Edges,Polygon Visualization,Microsoft SQL Server Sink,MQTT Writer,Icon Visualization,PLC ModbusTCP,Anthropic Claude,Rich Label Visualization,Identify Changes,Twilio SMS/MMS Notification,Keypoint Visualization,Image Preprocessing,Image Slicer,OpenAI,Clip Comparison,Line Counter,Anthropic Claude,Text Display,Image Stack,Qwen 3.6 API,Grid Visualization,Model Comparison Visualization,Florence-2 Model,PTZ Tracking (ONVIF),Identify Outliers,Mask Visualization,Classification Label Visualization,OpenAI,Pixelate Visualization,Roboflow Visual Search,VLM As Detector - outputs:
PLC Writer,Track Class Lock,Byte Tracker,Path Deviation,Crop Visualization,VLM As Detector,Object Detection Model,Polygon Visualization,Detections Stabilizer,Webhook Sink,VLM As Classifier,Motion Detection,SAM 3 Interactive,Keypoint Detection Model,Clip Comparison,YOLO-World Model,Buffer,OC-SORT Tracker,Slack Notification,Label Visualization,MoonshotAI Kimi,PLC Reader,Stitch OCR Detections,Label Visualization,Instance Segmentation Model,Email Notification,Keypoint Detection Model,Velocity,BoT-SORT Tracker,Detection Event Log,Overlap Analysis,Single-Label Classification Model,OPC UA Writer Sink,Ellipse Visualization,Path Deviation,Corner Visualization,Triangle Visualization,Detection Offset,Qwen-VL,Distance Measurement,Camera Calibration,Seg Preview,Google Gemini,Polygon Zone Visualization,Roboflow Custom Metadata,LMM For Classification,SIFT Comparison,Trace Visualization,Object Detection Model,Color Visualization,Llama 3.2 Vision,SAM3 Video Tracker,Llama 3.2 Vision,Dynamic Zone,SAM2 Video Tracker,Google Gemma API,Detections Filter,Google Gemma,Microsoft SQL Server Sink,Polygon Visualization,Icon Visualization,Detections Transformation,Rich Label Visualization,Twilio SMS/MMS Notification,Keypoint Visualization,OpenAI,Object Detection Model,Keypoint Detection Model,Clip Comparison,Qwen 3.6 API,Instance Segmentation Model,Single-Label Classification Model,Mask Visualization,Nearest Neighbor Detection Match,OpenAI,Byte Tracker,Instance Segmentation Model,VLM As Detector,Blur Visualization,Multi-Label Classification Model,Frame Delay,Bounding Box Visualization,Roboflow Dataset Upload,Reference Path Visualization,OpenAI,Anthropic Claude,Google Gemini,Detections Stitch,Event Writer,Cache Set,Stitch OCR Detections,Time in Zone,VLM As Classifier,Email Notification,Template Matching,Mask Area Measurement,Perspective Correction,Detections List Roll-Up,Halo Visualization,Overlap Filter,Multi-Label Classification Model,Dynamic Crop,OpenRouter,Detections Consensus,PLC EthernetIP,GeoTag Detection,Per-Class Confidence Filter,Halo Visualization,Line Counter Visualization,Time in Zone,Time in Zone,Roboflow Asset Library Attributes,Multi-Label Classification Model,Size Measurement,Detections Combine,SAM 3,ByteTrack Tracker,Dot Visualization,Florence-2 Model,Background Color Visualization,Google Gemini,Roboflow Dataset Upload,Segment Anything 2 Model,MoonshotAI Kimi,Qwen 3.5 API,Stability AI Inpainting,SAM 3,Camera Focus,Line Counter,Instance Segmentation Model,Circle Visualization,Detections Merge,Google Gemini,Detections Classes Replacement,Roboflow Vision Events,Model Monitoring Inference Aggregator,Single-Label Classification Model,Heatmap Visualization,Twilio SMS Notification,MQTT Writer,SAM 3,Anthropic Claude,SORT Tracker,Gaze Detection,Line Counter,Anthropic Claude,Text Display,Image Stack,PTZ Tracking (ONVIF),Model Comparison Visualization,Florence-2 Model,Grid Visualization,Classification Label Visualization,Byte Tracker,Pixelate Visualization
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Motion Detection in version v1 has.
Bindings
-
input
image(image): The input image or video frame to analyze for motion. The block processes frames sequentially to build a background model - each frame updates the background model and detects motion relative to learned background patterns. Can be connected from workflow inputs or previous steps..minimum_contour_area(integer): Minimum area in square pixels for a motion region to be detected. Contours smaller than this threshold are filtered out to ignore noise, small shadows, or minor pixel variations. Lower values increase sensitivity but may detect more false positives (e.g., 100 for very sensitive detection, 500 for only large objects). Default is 200 square pixels..morphological_kernel_size(integer): Size of the morphological kernel in pixels used to combine nearby motion regions and filter noise. Larger values merge more distant motion regions into single contours but may also merge separate objects. Smaller values preserve more detail but may leave fragmented detections. The kernel uses an elliptical shape. Default is 3 pixels..threshold(integer): Threshold value for the squared Mahalanobis distance used by the MOG2 background subtraction algorithm. Controls sensitivity to motion - smaller values increase sensitivity (detect smaller changes) but may produce more false positives, larger values decrease sensitivity (only detect significant changes) but may miss subtle motion. Recommended range is 8-32. Default is 16..history(integer): Number of previous frames used to build the background model. Controls how quickly the background adapts to changes - larger values (e.g., 50-100) create a more stable background model that's less sensitive to temporary changes but adapts slowly to permanent background changes. Smaller values (e.g., 10-20) allow faster adaptation but may treat moving objects as background if they stop moving. Default is 30 frames..detection_zone(Union[zone,list_of_values]): Optional polygon zone to limit motion detection to a specific area of the frame. Motion is only detected within this zone, ignoring activity outside. Format: [[x1, y1], [x2, y2], [x3, y3], ...] where coordinates are in pixels. The polygon must have more than 3 points. Can be provided as a list, JSON string, or selector referencing zone outputs from other blocks. Useful for focusing on specific regions (e.g., doorways, windows, restricted areas) while ignoring busy but irrelevant areas. If not provided, motion is detected across the entire frame..suppress_first_detections(boolean): If true, suppresses motion detections until the background model has been initialized with enough frames (specified by the history parameter). This prevents false positives from early frames where the background model hasn't learned the scene yet. When false, the block attempts to detect motion immediately, which may produce unreliable results during initialization. Default is true (recommended for most use cases)..
-
output
motion(boolean): Boolean flag.alarm(boolean): Boolean flag.detections(object_detection_prediction): Prediction with detected bounding boxes in form of sv.Detections(...) object.motion_zones(list_of_values): List of values of any type.
Example JSON definition of step Motion Detection in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/motion_detection@v1",
"image": "$inputs.image",
"minimum_contour_area": 200,
"morphological_kernel_size": 3,
"threshold": 16,
"history": 30,
"detection_zone": "<block_does_not_provide_example>",
"suppress_first_detections": true
}