This project is to build a simple motion detection gadget that can describe the motion as it is detected by the camera
cat /etc/os-release
Raspian on raspberry pi
PRETTY_NAME = "Raspian GNU/Linux 10 (buster)
VERSION="10(buster)"
ID =raspian
ID_LIKE=debian
sudo apt-get update
sudo apt full-upgrade
The whole solution includes the following: configurations on RaspberryPi and DoorBell.sln that includes following projects:
- DoorBell.AzureFunction
- DoorBell.DataContracts
- DoorBell.Storage
- DoorBell.Web
- On RaspberryPi, motion library is used to capture and record motion. The updated motion.conf file is included in the repo
- A custom python (uploadFile.py) file is added to RaspberryPi. This file connects with the IotHub. Once the motion library saves the motion as .mp4 file, it executes the uploadFile.py. This file extracts frames from the .mp4 file, uploads the frames and the original mp4 file to a blob storage using the IoTHub's file upload mechanism and then sends a message to the IotHub that a new event happened including the details.
The azure function gets triggered everytime the IotHub receives a message. The function does the following:
- For each frame (jpg) file stored (by the RaspberryPi), calls Azure Computer Vision sdk to get different vision features (including the captions) for that image.
- Store the details received from the Azure Computer Vision service along with the message in the Cosmos DB.
This is data contracts library that is used across the projects.
This is a web api that wraps around the CosmosDB to save and fetch device messages along with the processed information received from the Azure Computer Vision service.
This is a webApp that shows the events, captions (description) received from Azure Computer Vision services along with the original video (mp4) file recorded by the RaspberryPi
use pip3 to use python 3
use --user option when installing python libraries in the user's python install directory
From the project repo run pip3 install to install all the required packages
pip3 install -r requirements.txt --user
Setup azure credentials for keyvault.
login to shell.azure.com/bash
az ad sp create-for-rbac --name http://my-application --skip-assignment
export AZURE_CLIENT_ID="generated app id"
export AZURE_CLIENT_SECRET="random password"
export AZURE_TENANT_ID="tenant id"
Authorize the service principal to perform key operations in your Key Vault:
az keyvault set-policy --name my-key-vault --spn $AZURE_CLIENT_ID --secret-permissions get set list
- RaspberryPi docs: https://www.raspberrypi.org/documentation/raspbian/
- Motion library on RaspberryPi (version 4.1.1):https://motion-project.github.io/4.1.1/motion_guide.html
- Azure IotHub Python samples: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-python-python-file-upload
- CosmosDb Samples: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-dotnet-v3sdk-samples
- Azure Functions: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-iot
Sorry, the code repo is still kept private :)
The screenshot below has the high level architecture design and how the data flows thru the system
Here is a screenshot from the DoorBell.Web app of the results: Events List:
Event Description with original video: