This Python script utilizes OpenCV to capture video from a webcam and detect motion within the frame. When motion is detected, the script captures an image of the object and sends an email notification with the image attached. It serves as a basic but effective home security solution.
-
Motion Detection: Monitors the video feed for any movement in the frame.
-
Email Alert: Sends an email alert with an image attachment when motion is detected.
-
Run the script
main.py
. -
The script captures video from the default camera (usually your webcam).
-
It constantly compares frames to detect motion.
-
When motion is detected, it captures an image of the object and sends an email notification.
-
The script continues monitoring for motion until you press 'q' to quit.
Before using this script, ensure you have the following libraries and configurations in place:
- OpenCV: Required for capturing and processing video frames.
- Python: Python 3.x is recommended.
- An SMTP email account to send email notifications.
- Imghdr: For determining the image file type.
-
Configure your email credentials by setting
SENDER
,PASSWORD
, andRECEIVER
in theemailing.py
file. The password can be set as an environment variable for security. -
Customize the email message, subject, and content as needed in the
send_email
function. -
Adjust motion detection settings and image capture frequency to suit your preferences.
-
This script is a basic home security solution and can be enhanced with additional features such as video recording, more sophisticated motion detection algorithms, or integration with external security systems.
-
Ensure that you run the script with the appropriate camera device, which is set to 0 for the default camera.
-
It's recommended to run the script in a headless environment for practical security applications.
That's it! Use this script to create a simple yet effective motion detection and email alert system to enhance your home security.
This project is licensed under the MIT License. You are free to use and modify the code for your own purposes.