This project uses a local YOLOv8 custom PPE model to detect the presence of PPE with a Meraki MV Camera. PPE Zones are defined to specify what a full 'PPE Kit' looks like per camera. If one or more PPE violations are detected, a Microsoft Teams message is sent to a notification space with an attached snapshot.
Supported PPE:
PPE Detection States:
Valid
: Full Kit DetectedInvalid
: One or More Missing PPE Pieces Detected (send Microsoft Teams Message)Unknown
: Unable to Detect All Pieces of PPE in KitNote: Due to the nature of ML, this model is highly trained for the original use case. Accuracy and performance millage will vary.
Refer to the image dataset to view the raw image set and information around model accuracy, class ids, etc. Raw image set is NOT included in this repo.
Model Performance Graphs can be found under ppe_app/detection/ppe_dataset/
, for example:
In order to use the Meraki API, you need to enable the API for your organization first. After enabling API access, you can generate an API key. Follow these instructions to enable API access and generate an API key:
Organization > Settings > Dashboard API access
Enable access to the Cisco Meraki Dashboard API
My Profile > API access
Generate API key
For more information on how to generate an API key, please click here.
Note: You can add your account as Full Organization Admin to your organizations by following the instructions here.
MQTT Broker: MQTT-based protocols use a publish-subscribe connection between the client and server. In the case of MV Sense, the server is continuously pushing messages to the MV smart cameras so the device can respond instantly. This leads to a real-time feed of data coming from your camera. Follow these steps to configure a MQTT broker:
Cameras > Monitor > Cameras
and selecting the camera you would like to enable MV Sense on.Settings > Sense
.Enabled
.Add or edit MQTT Brokers
.Note: For testing/trial you can find a public broker here.
For more information on using MQTT with Meraki cameras, please click here.
Note: If this is your organization's first time using MV Sense, you will have 10 free perpetual licenses available to use. If you have exceeded this 10 free license count, you must activate more licenses by navigating to
Organization > Configure > License Info
and claim more licenses.
To send annotated snapshots in Microsoft Teams messages, it's required for images to be available at a public URL. A separate flask app (microsoft_teams_app/serve_images.py
) can be run on http://localhost:3500 to serve images from the microsoft_teams_app/hosted_images
directory, but ngrok is required to make the app publicly reachable. It's recommended in production to use a cloud based solution for uploading and using the images (AWS S3, etc.).
Follow these instructions to set up ngrok:
Getting Started
> Your Authtoken
on the menu on the left-hand side. Copy the token on this page.ngrok authtoken [yourtoken]
replacing [yourtoken] with the authtoken you copied in Step 2.
ngrok http 3500
A central part of the app is defining camera's to observe and what defines a full 'PPE Kit'. All relevant files are found in: ppe_app
.
Rename cameras_sample.json
to cameras.json
and ppe_zones_sample.json
to ppe_zones.json
cameras.json
:Define which cameras to run the model on here. Refer to the image below for the definition of each field.
Note: 'ppe_zone_name' must map to a name defined in ppe_zones.json
. 'camera_location' is an optional additional field for verbosity in the Microsoft Teams Card (static/cards/default_card.json
). More fields can easily be added to the card (with some reworking of the code as well).
ppe_zones.json
Define new PPE Zones and what PPE Items to enforce here. Refer to the image below for the definition of each field.
Note: To enforce PPE Items, enter true
, otherwise enter false
.
A Camera Zone can optionally be specified. If specified, only people detected in the zone will trigger the PPE detection.
Cameras > Monitor > Cameras
and selecting the camera you would like to create a zone on.Settings > Zones
.This app also includes a dashboard to view live snapshot annotations compared to live video traffic from the camera. In order to get the live feed (via RTSP), ensure the MV is locally reachable from the app.
Note: locally reachable MVs are not strictly required for the primary solution, just for the RTSP stream on the dashboard.
This app provides several Docker
files for easy deployment. Docker
is the recommended deployment method. Install Docker
here.
git clone [repository name]
ppe_app/detection/config_sample.py
).env
:MERAKI_API_KEY = "" MERAKI_ORG_NAME = ""
config.py
):# MQTT (snapshot mode) MQTT_SERVER = "" MQTT_PORT = 0
config.py
. If run locally with docker, uncomment the relevant URLs. By default, each app can run without being exposed to the internet. If pieces of the app are deployed in different locations, updated the URLs accordingly.# PPE Detection/Primary Flask URL (public/private) - running locally with python VISUALIZATION_APP_URL = "http://127.0.0.1:4000" HOSTING_APP_URL = "http://127.0.0.1:3500" # Use the below values if deploying via docker # VISUALIZATION_APP_URL = "http://ppe_visualization_dashboard:4000" # HOSTING_APP_URL = "http://microsoft_teams_app:3500"
config.py
. This URL is most likely the Ngrok URL from the prerequisites or public URL.# Serving Images Flask URL (public) SERVE_IMAGES_URL = ""
.env
) (only relevant if serving images with flask app previously discussed)# Microsoft Teams Integration MICROSOFT_TEAMS_URL = "" IMAGE_RETENTION_DAYS = 1
pip3 install -r requirements.txt
To run the program, use the docker command:
$ docker-compose up -d --build
To run individually with python (top-level-directory), there are several pieces of code to execute.
Start by running the primary flask app ppe_app/visualization_dashboard/app.py
. This connects with ppe_detection.py
and launches the visualization dashboard.
$ python3 ppe_app/visualization_dashboard/app.py
Then launch secondary flask app microsoft_teams_app/serve_images.py
. This app makes hosted images available to Microsoft Teams Messages.
$ python3 microsoft_teams_app/serve_images.py
Finally, run ppe_app/detection/ppe_detection.py
. This starts the MQTT server, and runs the PPE Detection on snapshots taken when a person is detected.
$ python3 ppe_app/detection/ppe_detection.py
Once running, detection console output looks like:
When a violation is detected, a Microsoft Teams Card is sent which looks like:
Navigate to the url of app.py
to select a camera, and view the live visualization dashboard. The left hand video shows RTSP live video, and the right side shows the most recent annotated snapshot.
The most recent snapshots, annotated images, and hosted images can be found in the following directories:
Provided under Cisco Sample Code License, for details see LICENSE
Our code of conduct is available here
See our contributing guidelines here
Please note: This script is meant for demo purposes only. All tools/ scripts in this repo are released for use "AS IS" without any warranties of any kind, including, but not limited to their installation, use, or performance. Any use of these scripts and tools is at your own risk. There is no guarantee that they have been through thorough testing in a comparable environment and we are not responsible for any damage or data loss incurred with their use.
You are responsible for reviewing and testing any scripts you run thoroughly before use in any non-testing environment.
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community