Skip to content

Motion Detection

Class: MotionDetectionBlockV1

Source: inference.core.workflows.core_steps.classical_cv.motion_detection.v1.MotionDetectionBlockV1

This block uses background subtraction to detect motion in a video. The block draws the contours of the detected motion, as well as outputs the bounding boxes as an object detection. Two flags are provided for use in workflows - one to indicate motion, and an alarm to indicate when the motion changed from no motion to motion detected. Additionally a zone can be provided to limit the scope of the motion detection to a specific area of the video frame.

Motion detection is extremely useful for generating alerts and file uploads. Additionally, inference can be conditionally run based on motion detection to save compute resources.

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 Motion in areas smaller than this in square pixels will not be counted as motion..
morphological_kernel_size int The size of the kernel in pixels used for morphological operations to combine contours..
threshold int The threshold value for the squared Mahalanobis distance for background subtraction. Smaller values increase sensitivity to motion. Recommended values are 8-32..
history int The number of previous frames to use for background subtraction. Larger values make the model less sensitive to quick changes in the background, smaller values allow for more adaptation..
detection_zone Union[List[Any], str] An optional polygon zone in a format [[x1, y1], [x2, y2], [x3, y3], ...]; each zone must consist of more than 3 points.
suppress_first_detections bool Suppress motion detections until the background history is fully initialized..

The Refs column marks possibility to parametrise the property with dynamic values available in workflow runtime. See Bindings for more info.

Available Connections

Compatible Blocks

Check what blocks you can connect to Motion Detection in version v1.

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 for this step..
    • minimum_contour_area (integer): Motion in areas smaller than this in square pixels will not be counted as motion..
    • morphological_kernel_size (integer): The size of the kernel in pixels used for morphological operations to combine contours..
    • threshold (integer): The threshold value for the squared Mahalanobis distance for background subtraction. Smaller values increase sensitivity to motion. Recommended values are 8-32..
    • history (integer): The number of previous frames to use for background subtraction. Larger values make the model less sensitive to quick changes in the background, smaller values allow for more adaptation..
    • detection_zone (Union[list_of_values, zone]): An optional polygon zone in a format [[x1, y1], [x2, y2], [x3, y3], ...]; each zone must consist of more than 3 points.
    • suppress_first_detections (boolean): Suppress motion detections until the background history is fully initialized..
  • output

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
}