This project detects humans in a live webcam feed using a MobileNet-SSD model. It saves screenshots when a person is detected and logs the duration of their presence, also starts video recording if the person stays for too long. The script can be run as a command-line tool on Linux or as a Python script on other platforms.
- Real-time human detection using a pre-trained MobileNet-SSD model.
- Saves screenshots when a person is detected.
- Logs detection durations in a CSV file.
- Starts recording if the intruder stays for too long.
- Customizable configuration via
config.json
.
git clone https://github.com/FarhanSadaf/webcam.git
cd webcam
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
chmod +x webcam
-
Without showing the video feed:
./webcam
-
Video Recording Disabled:
./webcam --novideo
-
With the video feed:
./webcam --show
-
Print detection statistics:
./webcam --stat
-
Print detection statistics for the last N days (e.g., last 2 days):
./webcam --stat 2
-
Print top M results for the last N days (e.g., top 2 results for the last 3 days):
./webcam --stat 3 -top 2
-
Delete output directories for specific days:
./webcam --delete
To use webcam
as a global command:
sudo mv webcam /usr/local/bin/
Run the Python Script Directly:
-
Without showing the video feed:
python main.py
- Video Recording Disabled:
python main.py --novideo
-
With the video feed:
python main.py --show
-
Print detection statistics:
python main.py --stat
-
Print detection statistics for the last N days (e.g., last 2 days):
python main.py --stat 2
-
Print top M results for the last N days (e.g., top 2 results for the last 3 days):
python main.py --stat 3 -top 2
-
Delete output directories for specific days:
python main.py --delete
Modify config.json
to customize the behavior:
model_weights
: Path to the model weights file.model_config
: Path to the model configuration file.frame_rate
: Desired frame rate.input_size
: Input size for the model.output_folder
: Folder to save screenshots and logs.camera_id
: Change video capture camera.second_screenshot_interval
: Time (sec.) after second screenshot will be taken or video recording will be started.recording_duration
: Minimum amount of time (sec.) the video will be recorded.coverage_threshold
: Average brightness threshold for dark frames. Adjust it according to your environment.
Screenshots are saved in the output/<date>/
folder with timestamps.
Detection durations are logged in output/<date>/detection_durations.csv
.
Use --stat
to print the CSV log in a table:
+---------------------------+-------------------+
| Filename | Duration (seconds)|
+---------------------------+-------------------+
| 2023-10-01_12-34-56_#1.jpg| 3.45 |
| 2023-10-01_12-35-10_#2.jpg| 7.89 |
+---------------------------+-------------------+
This project is licensed under the MIT License. See LICENSE
for details.
Feel free to open issues or submit pull requests. Contributions are welcome!