Previous
Run inference
Triggers can send alerts in the form of email notifications or webhook requests when new data syncs to the cloud.
This guide shows you how to set up an alert system that notifies you when specific objects or classifications are detected in your camera feed. The process involves three resources:
For example, a trigger could alert you when a camera feed detects an anomaly.
Before setting up alerts, you need:
The filtered-camera
module functions as a normal camera unless used with the data management service.
When you configure the data management service to capture and sync images from the camera, the camera will only pass images to the data management service if they meet the defined criteria.
The camera module takes a vision service and applies it to a camera feed using the generated predictions to filter the output for the data management service.
Configure the filtered camera module to capture images when specific predictions occur:
Navigate to your machine’s CONFIGURE tab.
Click the + (Create) button next to your main part in the left-hand menu and select Component or service.
Start typing filtered-camera
and select camera / filtered-camera from the results.
Click Add module.
Name your filtering camera something like objectfilter-cam
and click Create.
Paste a configuration into the attributes field:
Replace the <camera_name>
and <vision_service_name>
values with the names of your camera and vision service.
Choose your detection type:
objects
configuration with the label you want to alert on and remove classifications
classifications
configuration with the label you want to alert on and remove objects
The confidence threshold (0.0-1.0) determines how certain the vision model must be before capturing photos.
For example, a confidence threshold of 0.6
only captures photos when the vision model is at least 60% sure that it has correctly identified the desired label.
{
"camera": "<camera_name>",
"vision_services": [
{
"vision": "<vision_service_name>",
"classifications": { "<label>": 0.5 },
"objects": { "<label>": 0.5 }
}
]
}
For example, if using the YOLOv8 model (named yolo
) for hard hat detection as demonstrated in the Monitor Helmet Usage tutorial:
{
"camera": "my_webcam",
"vision_services": [
{
"vision": "yolo",
"objects": {
"NO-Hardhat": 0.6
}
}
]
}
Click Save in the top right corner of the screen to save your changes.
For more information, see the filtered-camera
module README.
Viam provides a way to monitor detections, classifications, and confidence levels from a live vision service. To view this information, navigate to the vision service card and expand the TEST panel. You can use this to verify your confidence level configuration.
The data management service captures data and syncs it to the Viam cloud. This step connects your filtered camera to the cloud so that detected images can trigger alerts.
Configure data capture on the filtered-camera
resource to capture images of detections or classifications:
Add the data management service to your machine:
Navigate to your machine’s CONFIGURE tab.
Click the + (Create) button next to your main part in the left-hand menu and select Component or service.
Enter “data” and select data management.
Name your data management service data-manager
and click Create.
Leave all the default data service attributes as they are and click Save in the top right corner of the screen to save your changes.
Enable data capture on your filtered camera:
Locate the objectfilter-cam
panel.
Click Add method.
Click the Type dropdown and select ReadImage.
Set the capture frequency to 0.2
images per second (equivalent to one image every 5 seconds).
You can adjust the frequency to suit your use case.
Set the MIME type to image/jpeg
.
Triggers send webhook requests or email notifications when certain events happen:
Since the filtered camera only captures images that meet the specified criteria, it only syncs images when a label is identified. Therefore, if you configure a filtered camera to capture images when an anomaly is detected, an image of the anomaly gets synced, a trigger fires, and an alert is sent.
Follow these steps to configure a trigger to alert when filtered-camera
syncs an image:
Go to the CONFIGURE tab of your machine. Click the + (Create) button in the left side menu and select Trigger.
Enter a name and click Create.
In the Type dropdown, select Data has been synced to the cloud.
In the Data Types dropdown, select Binary (image).
Add notification methods to the Webhooks or Email sub-panels:
To add an email notification:
Click Add Email.
Add the email address you wish to be notified whenever this trigger fires.
To add a webhook notification:
Click Add Webhook.
Add the URL of your cloud function.
Write your cloud function to process the webhook data. Use your cloud function to process data or interact with external APIs, such as Twilio, PagerDuty, or Zapier.
Configure the notification frequency (for example, maximum one alert per hour).
Click Save in the top right corner of the screen to save your configuration.
Verify your setup:
viam-server
is running on your machineTest the detection:
Monitor the data flow:
If you’re getting too many false positives, increase your confidence threshold in the filtered camera configuration.
If you receive too many alerts and want to limit them to once per hour maximum, adjust the notification frequency in your trigger settings.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!