Python · Shipped
Webcam Alert
Real-time motion detection using OpenCV to monitor webcam activity and trigger alerts.
Repository★ 1
Python
A Python-based security system that uses your computer's webcam to detect motion and send email alerts with captured images when movement is detected.
Features #
- Real-time motion detection using webcam
- Automatic email notifications with captured images
- Configurable motion sensitivity
- Clean and efficient image management
- Multi-threaded processing for better performance
Requirements #
- Python 3.x
- OpenCV (cv2)
- SMTP access for email functionality
- python-dotenv (for environment variables)
Installation #
- Clone the repository:
git clone https://github.com/AhmadTawil1/webcam-alert.git
cd webcam-alert
- Install the required packages:
pip install opencv-python python-dotenv
- Configure email settings:
- Create a new file named
.envin the project root directory - Add the following variables to the
.envfile:EMAIL_PASSWORD=your_email_app_password EMAIL_SENDER=your_email@gmail.com EMAIL_RECEIVER=recipient_email@gmail.com - Replace the values with your actual email credentials
- Make sure to use an app password for Gmail (not your regular password)
- Never commit the
.envfile to version control
- Create a new file named
Usage #
- Run the main script:
python main.py
-
The program will:
- Start your webcam
- Begin monitoring for motion
- Send email alerts when motion is detected
- Save captured images in the
imagesdirectory
-
Press 'q' to quit the program
How It Works #
The system uses computer vision techniques to:
- Capture video from the webcam
- Convert frames to grayscale and apply Gaussian blur
- Compare consecutive frames to detect motion
- When significant motion is detected:
- Capture and save the image
- Send an email notification with the image attached
- Clean up old images
Security Note #
- The system uses Gmail's SMTP server for sending emails
- Email credentials are stored in environment variables for security
- Make sure to use an app password instead of your main email password
- Keep your
.envfile secure and never share it - The
.envfile is already in.gitignoreto prevent accidental commits
Contributing #
Feel free to submit issues and enhancement requests!
License #
This project is open source and available under the MIT License.