Set of scripts for motion detection and a DIY security camera on PC and Raspberry Pi
The setup and usage are described in detail in this video: https://youtu.be/Jb_5d0TSlAw
To help support this software and other open-source projects, please consider subscribing to my YouTube channel: https://www.youtube.com/@jeoresearch
- Detects motion using OpenCV.
- Sends email notifications with images attached when motion is detected.
- Configurable cooldown period between email alerts.
- Compatible with the Raspberry Pi Camera Module and USB webcams.
- Raspberry Pi (with camera module or USB webcam)
- Python 3
- Libraries:
opencv-python
numpy
smtplib
picamera2
(for Raspberry Pi Camera Module)
Install the required dependencies:
sudo apt update
sudo apt install -y python3-opencv python3-numpy python3-picamera2
-
Clone the repository:
git clone https://github.com/your-username/SecurityCamPi.git cd SecurityCamPi
-
Ensure the script is executable:
chmod +x SecurityCamPi.py
-
Test the script:
python3 SecurityCamPi.py
-
Edit the script
SecurityCamPi.py
to configure email details:sender_email = "[email protected]" # Replace with the new email (for sending from Pi) receiver_email = "[email protected]" # Replace with your email (for receving images) password = "aaaabbbbccccdddd" # Replace with your app password
-
Run the script manually:
python3 SecurityCamPi.py
To configure the script to start at boot:
-
Create a systemd service file:
sudo nano /etc/systemd/system/SecurityCamPi.service
-
Add the following content and replace "user" in /home/user and User=user with your login:
[Unit] Description=Motion Detection Script After=multi-user.target [Service] ExecStart=/usr/bin/python3 /home/user/SecurityCamPi.py WorkingDirectory=/home/user User=user Restart=always [Install] WantedBy=multi-user.target
-
Enable the service:
sudo systemctl enable SecurityCamPi.service sudo systemctl start SecurityCamPi.service
-
Motion Sensitivity: Adjust
min_movement_area
in the script to set the minimum size of detected objects:min_movement_area = 500
-
Email Cooldown: Set the cooldown period (in seconds) between email alerts:
email_cooldown = 20
-
Headless Mode: To run without OpenCV windows, comment out the following lines in the script:
cv2.imshow("Webcam Feed", frame) cv2.imshow("PMOG Visualization", fgmask)
Contributions are welcome! Feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.