This project demonstrates how to analyze camera feed stored as Redis Streams using serverless engine RedisGears, RedisAI and display analyzed frames with metrics in Grafana.
Demo is available on demo.volkovlabs.io:
This project provides Docker image with Redis, RedisTimeSeries, RedisGears, RedisAI and installed OpenCV for Python library.
docker run -p 6379:6379 --name=redis-opencv ghcr.io/redisgrafana/redis-opencv:latest
Check that OpenCV with dependencies downloaded, installed and registered in the RedisGears requirements:
cluster.remote:6379> rg.pydumpreqs
1) 1) "GearReqVersion"
2) (integer) 1
3) "Name"
4) "Pillow"
5) "IsDownloaded"
6) "yes"
7) "IsInstalled"
8) "yes"
9) "CompiledOs"
10) "linux-buster-x64"
11) "Wheels"
12) 1) "Pillow-8.2.0-cp37-cp37m-manylinux1_x86_64.whl"
2) 1) "GearReqVersion"
2) (integer) 1
3) "Name"
4) "opencv-python"
5) "IsDownloaded"
6) "yes"
7) "IsInstalled"
8) "yes"
9) "CompiledOs"
10) "linux-buster-x64"
11) "Wheels"
12) 1) "numpy-1.20.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl"
2) "opencv_python-4.5.2.52-cp37-cp37m-manylinux2014_x86_64.whl"
3) 1) "GearReqVersion"
2) (integer) 1
3) "Name"
4) "numpy"
5) "IsDownloaded"
6) "yes"
7) "IsInstalled"
8) "yes"
9) "CompiledOs"
10) "linux-buster-x64"
11) "Wheels"
12) 1) "numpy-1.20.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl"
To load AI model and PyTorch script to the Redis database run:
cd ai/
cat tiny-yolo-voc.pb | redis-cli -h redis -x AI.MODELSTORE yolo:model TF CPU INPUTS 1 input OUTPUTS 1 output BLOB
cat ai-yolo-script.py| redis-cli -h redis -x AI.SCRIPTSET yolo:script CPU SOURCE
Grafana can be started using Docker Compose or installed locally with Redis plug-ins for Grafana and Volkov Labs Image panel.
docker-compose pull
docker-compose up
When starting using Docker Compose, dashboard and plug-ins will be auto-provisioned and available in Grafana.
Select Camera Processing
dashboard and copy-paste gears-yolo.py
script to RedisGears Script editor panel.
Click on the Run script
button and you should see registered script StreamReader
in the Registrations panel.
Copy script edge-camera.py
and requirements.txt
to IoT or any device with camera. Run script by specifying Redis URL, number of frames per second and rotate camera if required.
cd camera/
pip3 install -r requirements.txt
python3 edge-camera.py -u redis://redis:6379 --fps 6 --rotate-90-clockwise true
You should see output with Stream's Id and size of the jpeg file.
# python3 camera.py -u redis://red:6379 --fps 6 --rotate-90-clockwise true
Connected to Redis: ParseResult(scheme='redis', netloc='redis:6379', path='', params='', query='', fragment='')
id: b'1622145939609-0', size: 5479
id: b'1622145939769-0', size: 10006
id: b'1622145939928-0', size: 6709
id: b'1622145940100-0', size: 6037
id: b'1622145940266-0', size: 6468
id: b'1622145940435-0', size: 11607
id: b'1622145940597-0', size: 5577
id: b'1622145940768-0', size: 6041
id: b'1622145940926-0', size: 5570
id: b'1622145941098-0', size: 5916
- Redis plug-ins for Grafana Documentation
- My Other Stack Is RedisEdge
- RedisEdge Real-time Video Analytics
- Fork the repository.
- Find an issue to work on and submit a pull request.
- Could not find an issue? Look for documentation, bugs, typos, and missing features.
- Apache License Version 2.0, see LICENSE.