This repository provides a simple, efficient, and resource-light solution to set up a motion-detection security camera using a Raspberry Pi. The Python script utilizes OpenCV for video capture and motion detection.
- A Raspberry Pi with Raspbian OS installed.
- A camera module compatible with Raspberry Pi.
- Python 3.x installed on the Raspberry Pi.
The script uses the following Python libraries:
- OpenCV
- NumPy
You can install these using the following commands:
sudo apt-get update
sudo apt-get install python3-opencv
- Clone this repository to your Raspberry Pi.
- Update the
save_path
variable in theSecurityCam.py
script with the path where you'd like to save the captured images.
To run the script manually, navigate to the repository folder and execute:
python3 SecurityCam.py
Press q
to stop the script.
To have the script run automatically in the background upon Raspberry Pi startup, you can set up a systemd
service.
-
Open a new file in the
/etc/systemd/system/
directory:sudo nano /etc/systemd/system/motion_camera.service
-
Add the following content:
[Unit] Description=Motion Camera Service After=network.target [Service] ExecStart=/usr/bin/python3 /path/to/your/SecurityCam.py WorkingDirectory=/path/to/your/ StandardOutput=inherit StandardError=inherit Restart=always User=pi [Install] WantedBy=multi-user.target
Replace
/path/to/your/SecurityCam.py
with the full path to your Python script and/path/to/your/
with the directory where the script resides.
-
Reload the
systemd
daemon and enable the service:sudo systemctl daemon-reload sudo systemctl enable motion_camera.service
-
Start the service:
sudo systemctl start motion_camera.service
- To check the service status:
sudo systemctl status motion_camera.service
- To stop the service:
sudo systemctl stop motion_camera.service
- To restart the service:
sudo systemctl restart motion_camera.service
This project is licensed under the MIT License - see the LICENSE.md file for details.
Feel free to contribute to this project. For any issues or feature requests, please open an issue or submit a pull request.