|
1 |
| -# redis-camera-ai |
2 |
| -Analyze Camera capture using RedisAI |
| 1 | +# Analyzing camera captures using RedisAI, OpenCV and Grafana |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[](https://www.grafana.com) |
| 6 | +[](https://grafana.com/grafana/plugins/redis-datasource) |
| 7 | +[](https://grafana.com/grafana/plugins/redis-app) |
| 8 | +[](https://github.com/RedisGrafana/redis-camera-ai/actions/workflows/docker.yml) |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +This project demonstrates how to analyze camera frames stored as [Redis Streams](https://redis.io/topics/streams-intro) using serverless engine [RedisGears](https://oss.redislabs.com/redisgears/), [RedisAI](https://redisai.io/) and display analyzed frames with metrics in Grafana. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | +- [Docker](https://docker.com) to start Redis and Grafana. |
| 19 | +- [Python](https://www.python.org/) to run scripts. |
| 20 | + |
| 21 | +## Redis with OpenCV Docker image |
| 22 | + |
| 23 | +This project provides Docker image with Redis, RedisTimeSeries, RedisGears, RedisAI and installed [OpenCV for Python](https://docs.opencv.org/master/d6/d00/tutorial_py_root.html) library. |
| 24 | + |
| 25 | +Supported platforms are: |
| 26 | + |
| 27 | +- linux/amd64 |
| 28 | +- linux/arm64 |
| 29 | +- linux/arm |
| 30 | + |
| 31 | +```bash |
| 32 | +docker run -p 6379:6379 --name=redis-opencv ghcr.io/redisgrafana/redis-opencv:latest |
| 33 | +``` |
| 34 | + |
| 35 | +## OpenCV requirements |
| 36 | + |
| 37 | +Check that OpenCV with dependencies downloaded, installed and registered in the RedisGears requirements: |
| 38 | + |
| 39 | +``` |
| 40 | +cluster.remote:6379> rg.pydumpreqs |
| 41 | +1) 1) "GearReqVersion" |
| 42 | + 2) (integer) 1 |
| 43 | + 3) "Name" |
| 44 | + 4) "Pillow" |
| 45 | + 5) "IsDownloaded" |
| 46 | + 6) "yes" |
| 47 | + 7) "IsInstalled" |
| 48 | + 8) "yes" |
| 49 | + 9) "CompiledOs" |
| 50 | + 10) "linux-buster-x64" |
| 51 | + 11) "Wheels" |
| 52 | + 12) 1) "Pillow-8.2.0-cp37-cp37m-manylinux1_x86_64.whl" |
| 53 | +2) 1) "GearReqVersion" |
| 54 | + 2) (integer) 1 |
| 55 | + 3) "Name" |
| 56 | + 4) "opencv-python" |
| 57 | + 5) "IsDownloaded" |
| 58 | + 6) "yes" |
| 59 | + 7) "IsInstalled" |
| 60 | + 8) "yes" |
| 61 | + 9) "CompiledOs" |
| 62 | + 10) "linux-buster-x64" |
| 63 | + 11) "Wheels" |
| 64 | + 12) 1) "numpy-1.20.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl" |
| 65 | + 2) "opencv_python-4.5.2.52-cp37-cp37m-manylinux2014_x86_64.whl" |
| 66 | +3) 1) "GearReqVersion" |
| 67 | + 2) (integer) 1 |
| 68 | + 3) "Name" |
| 69 | + 4) "numpy" |
| 70 | + 5) "IsDownloaded" |
| 71 | + 6) "yes" |
| 72 | + 7) "IsInstalled" |
| 73 | + 8) "yes" |
| 74 | + 9) "CompiledOs" |
| 75 | + 10) "linux-buster-x64" |
| 76 | + 11) "Wheels" |
| 77 | + 12) 1) "numpy-1.20.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl" |
| 78 | +``` |
| 79 | + |
| 80 | +## Import AI model and script |
| 81 | + |
| 82 | +The loader script will load AI model and [PyTorch](https://pytorch.org/) script to the Redis database. |
| 83 | + |
| 84 | +``` |
| 85 | +cd src/ |
| 86 | +python3 ai-loader.py -u redis://redis:6379 |
| 87 | +``` |
| 88 | + |
| 89 | +## Start Grafana |
| 90 | + |
| 91 | +Grafana can be started using Docker Compose or installed locally with [Redis plug-ins for Grafana](https://redisgrafana.github.io) and [Volkov Labs Image panel](https://github.com/VolkovLabs/grafana-image-panel). |
| 92 | + |
| 93 | +``` |
| 94 | +docker-compose pull |
| 95 | +docker-compose up |
| 96 | +``` |
| 97 | + |
| 98 | +When starting using Docker Compose, dashboard and plug-ins will be auto-provisioned and available in Grafana. |
| 99 | + |
| 100 | +## Register RedisGears script |
| 101 | + |
| 102 | +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 `StreamReader` Registration. |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +## Start Camera |
| 107 | + |
| 108 | +Copy script `edge-camera.py` to IoT or any device with camera. Run script with specifing Redis URL, number of frames per second and rotate camera if required. |
| 109 | + |
| 110 | +``` |
| 111 | +python3 camera.py -u redis://redis:6379 --fps 6 --rotate-90-clockwise true |
| 112 | +``` |
| 113 | + |
| 114 | +## Learn more |
| 115 | + |
| 116 | +- Redis plug-ins for Grafana [Documentation](https://redisgrafana.github.io/) |
| 117 | +- [My Other Stack Is RedisEdge](https://redislabs.com/blog/my-other-stack-is-redisedge/) |
| 118 | +- [RedisEdge Real-time Video Analytics](https://github.com/RedisGears/EdgeRealtimeVideoAnalytics) |
| 119 | + |
| 120 | +## Contributing |
| 121 | + |
| 122 | +- Fork the repository. |
| 123 | +- Find an issue to work on and submit a pull request. |
| 124 | +- Could not find an issue? Look for documentation, bugs, typos, and missing features. |
| 125 | + |
| 126 | +## License |
| 127 | + |
| 128 | +- Apache License Version 2.0, see [LICENSE](https://github.com/RedisGrafana/redis-camera-ai/blob/main/LICENSE). |
0 commit comments