Security camera
PiCam is a complete security camera solution designed for the Raspberry Pi 4 B. It leverages OpenCV and MobileNet SSD to provide real-time person detection, automatically triggering video recording when activity is detected. The system features a Flask-based web interface that allows users to view a live feed, browse and play back saved recordings, and manages storage automatically with a 7-day data retention policy. It also includes a mock server mode for testing and development without requiring physical camera hardware.
Deployment Walkthrough
This guide explains how to deploy the security camera system on your Raspberry Pi 4 B.
Prerequisites
- Raspberry Pi 4 B with Raspberry Pi OS (Buster or newer).
- Camera module (connected via ribbon cable) or USB Webcam.
- Python 3 installed.
- Internet connection (for initial setup).
Installation
- Dependencies: Run the following command to install required system libraries (for OpenCV and Flask):
sudo apt-get update
sudo apt-get install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev libqtgui4 libqt4-test
pip3 install -r requirements.txt
- Models: The system relies on MobileNet SSD models. I have included a script to download them correctly:
python3 download_models.py
Ensure MobileNetSSD_deploy.prototxt and MobileNetSSD_deploy.caffemodel are present in the directory.
Running the Application
To start the security camera:
python3 main.py
Accessing the Enhanced Web Interface
- Find your Raspberry Pi's IP address: hostname -I
- Open a browser on another computer on the same network.
- Navigate to: http://<YOUR_PI_IP>:5000
Features The Interface is split into two tabs:
- Live View (Default)
- Shows the real-time camera feed.
- Recording Indicator: A pulsing red "Recording" badge appears when a person is detected.
- Note: Play/Pause controls have been removed for a streamlined experience.
- Recordings
- Click the "Recordings" tab to view saved clips.
- Browse: Clips are displayed in a grid/list.
- Play: Click on a clip to open the video player.
- Close Video: Click the "Close Video" button to stop playback and return to the list.
- Return to Live: Click the "Live View" tab at any time to immediately see the live feed.
Configuration
- Camera Orientation: If your camera is upside down, change flip=False to flip=True in main.py .
- Recording Duration: Default max duration is 10 minutes. You can adjust self.max_duration in recorder.py .
- Timeout: The recording stops if no person is detected for 5 seconds. Adjust self.person_timeout in recorder.py .
- Retention Policy: A background process automatically deletes files older than 7 days.