Skip to content

Using OpenCv and FastAPI, stream the current frame from a USB camera to the browser with detected motion.

License

Notifications You must be signed in to change notification settings

alexbenko/watch_cam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo of Motion Detector

demo.mp4

About

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.

    Info About My Pi

  • Model: Raspberry Pi4B
  • OS: Debian GNU/Linux 11 (Bullseye)
  • Ram: 4Gb
  • Storage Space: 256 Gb

Major To Do's

  1. Camera always on mode - currently camera only turns on when a user goes to the webpage. (mainly till i can do testing)
  2. Move image/video saving,getting,creating logic out of Camera model into their own (For watch_cam)
  3. Working docker-compose file for threaded_watch_cam
  4. Production server
  5. Optimize uploading to google drive. Worked perfectly for about 2 days, but then stopped uploading for an unknown reason.(For threaded watch cam
  6. Support other cloud storage tech, like AWS' S3.
  7. Notification system for user to be notified on motion. (Text or Email)
  8. 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.
  9. Allow user to record audio in browser to play through Pi speaker. (might not be possible without https)
  10. Update UI to something fancier, probably Material UI.
  11. User auth so server can be publicy available.

Pi Set Up

  1. 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.

  2. Install Docker and Docker-Compose

  3. Attatch a USB camera(required) and attatch a speaker (optional)

  4. Copy the docker-compose file to wherever you want to run it and change any environment variables in a .env file.

  5. 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.

  6. Type:

    sudo docker-compose up
  7. If everything is set type in your browser: [your pis local IP address]:[your specified port env]/

  8. 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.



Folders

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.



  1. recordings - Where each frame of detected motion will be saved to sorted by the day.
  2. audio - Where you can put mp3 files that will play through the speaker if desired.
  3. static - Where you can put static front end files. Like .js, .css , favicon.svg, etc. Currently only supports favicon.

Enviornment Variables to set

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 5000
  • HOST - 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.

About

Using OpenCv and FastAPI, stream the current frame from a USB camera to the browser with detected motion.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published