demo.mp4
Using OpenCv and Flask I am able to live stream a usb camera conneced to a Raspberry Pi to a browser with any detected motion. Really similar to how services like Arlo or any other smart camera works. Hopefully can be a replacement.
It has an estimated detection range of around 70-100 feet. I am almost postive this is due to my low quality USB camera and if I get one that can record in 1080 the range will be a lot farther. Have not tested for production and currently uses the development server from Flask.
- Model: Raspberry Pi4B
- OS: Debian GNU/Linux 11 (Bullseye)
- Ram: 4Gb
- Storage Space: 256 Gb
Camera always on mode - currently camera only turns on when a user goes to the webpage. (mainly till i can do testing)Move image/video saving,getting,creating logic out of Camera model into their own (For watch_cam)Working docker-compose file for threaded_watch_camProduction server- Optimize uploading to google drive. Worked perfectly for about 2 days, but then stopped uploading for an unknown reason.(For threaded watch cam
- Support other cloud storage tech, like AWS' S3.
- Notification system for user to be notified on motion. (Text or Email)
- Only upload new frames of motion. Currently just grabs todays folder and uploads it to my google drive without any logic to verify if the file has already been uploaded.
- Allow user to record audio in browser to play through Pi speaker. (might not be possible without https)
- Update UI to something fancier, probably Material UI.
- User auth so server can be publicy available.
First ensure you are running Raspberry Pi OS (or at least an arm64 distro) on A Raspberry Pi4 since the docker image is built off of
arm64v8/debian:bullseye
.Install Docker and Docker-Compose
Attatch a USB camera(required) and attatch a speaker (optional)
Copy the docker-compose file to wherever you want to run it and change any environment variables in a .env file.
Look at my compose file for reference, create a .env (look bellow for all that you can set) file in the same directory as your docker-compose file.
Type:
sudo docker-compose up
If everything is set type in your browser: [your pis local IP address]:[your specified port env]/
If you want to play audio, put desired .mp3 files into the /recordings in the same directory as your compose file and buttons will appear in either detector.
There will be 3 folders mounted from the docker image to your pi. Which is why I recommend you put the compose file into its own directory with its .env file. You can create them yourself or wait for docker to create them.
recordings
- Where each frame of detected motion will be saved to sorted by the day.audio
- Where you can put mp3 files that will play through the speaker if desired.static
- Where you can put static front end files. Like .js, .css , favicon.svg, etc. Currently only supports favicon.
There are a good amount of environment variables to set. Some arent that private and can be set in your compose file but others are more should be hidden in a .env file if it will be in a public repo.
To set a boolean env true, the value can be True, T, or 1. Any other value will be false and if it is not set, all booleans default to false
app_title
- String - The name of the app displayed in the tab and various webpages. Defaults to 'Cam'. (optional)save_images
- Boolean- Whether or not the server will save the images it detects motion/faces in. (optional)PORT
- The port you want the flask server to run on, defaults to 5000HOST
- Defaults to 0.0.0.0.TZ
- Timezone for time/date stamps.GUNICORN_WORKERS
- Number of workers for Gunicorn if you need to specify it. Otherwise defaults to the docs reccomendation of (2 x $num_cores) + 1.PRE_LOAD
- Defaults to True. Set this if you want to turn off the pre-load setting for gunicorn.
The next variables should be hidden from public view. Right now no user/password set up
EMAIL
- String - Email you want to use to forward texts if you desire. Currently only works with Gmail (optional).EMAIL_PASSWORD
- String - Password for your email account (required if you set EMAIL).PHONE_NUMBER
- String - The phone number you want texts to be forwarded to. (required if you set EMAIL and EMAIL_PASSWORD)CARRIER
- String - Name of your carrier. Currently only works with Verizon and AT&T. Valid options are 'att' or 'verizon' (required if you set EMAIL, EMAIL_PASSWORD, and PHONE_NUMBER)PYTHONUNBUFFERED
0 or 1 - After the initial start up prints, all other prints in the app are ignored. Set this to 1 if you still want to see prints.