Viam provides a motion-detector
model of the vision service with which you can detect the occurance and location of movement.
To transform your camera into a motion detecting camera, configure this vision service as a modular resource on your robot.
Start by configuring a camera on your robot. Remember the name you give to the camera, it will be important later.
Note
Before configuring your camera or vision service, you must create a robot.
Navigate to the Config tab of your robot’s page in the Viam app. Click on the Services subtab and click Create service. Select the vision
type, then select the motion-detector
model. Enter a name for your service and click Create.
On the new component panel, copy and paste the following attribute template into your base’s Attributes box.
{
"cam_name": "myCam",
"sensitivity": 0.9,
"min_box_size": 2000
}
Edit the attributes as applicable.
Note
For more information, see Configure a Robot.
The following attributes are available for viam:vision:motion-detector
vision services:
Name | Type | Inclusion | Description |
---|---|---|---|
cam_name |
string | Required | The name of the camera configured on your robot. |
min_box_size |
int | Required | The size (in square pixels) of the smallest bounding box to allow. Relevant for GetDetections/GetDetectionsFromCamera only. |
sensitivity |
float | Optional | A number from 0 - 1. Larger numbers will make the module more sensitive to motion. Default = 0.9 |
{
"modules": [
{
"type": "registry",
"name": "viam_motion-detector",
"module_id": "viam:motion-detector",
"version": "0.0.3"
}
],
"services": [
{
"name": "myMotionDetectionModule",
"type": "vision",
"namespace": "rdk",
"model": "viam:vision:motion-detector",
"attributes": {
"cam_name": "myCam",
"sensitivity": 0.9,
"min_box_size": 2000
}
}
]
}
This module is made for use with the following methods of the vision service API:
The module behavior differs slightly for classifications and detections.
When returning classifications, the module will always return a single classification with the class_name
"motion".
The confidence
of the classification will be a percentage equal to the percentage of the image that moved (more than a threshold determined by the sensitivity attribute).
When returning detections, the module will return a list of detections with bounding boxes that encapsulate the movement.
The class_name
will be "motion" and the confidence
will always be 0.5.
Once the viam:vision:motion-detector
modular service is in use, configure a transform camera to see classifications or detections appear in your robot's field of vision.
- To test your motion detector, configure a transform camera to see classifications or detections appear in your robot's field of vision from the Control tab.
- To write code to use the motion detector output, use one of the available SDKs.
Copyright 2021-2023 Viam Inc.
Apache 2.0