This project is designed to detect and count people from a live RTSP camera feed. It saves captured frames periodically, processes them to count the number of people detected, and generates reports and visualizations based on the detected data.
- Frame Extraction: Periodically captures frames from an RTSP camera feed.
- Person Detection: Processes captured frames to detect the number of people present.
- Real-time Monitoring: Displays the current number of people detected in a live JSON file.
- Daily Reporting: Generates a daily report and graph based on the detections between 08:10 AM and 05:05 PM.
- Threaded Operation: Frame capture and detection run concurrently using Python threads.
The project requires Python 3.10.14 and the following Python libraries:
opencv-python==4.8.0.76supervision==0.22.0inference==0.16.0python-dotenv==0.21.0matplotlib==3.7.1numpy==1.24.3
For the extraction module:
flaskflask-corsopencv-python-headlesspython-dotenvrequests
-
Clone the repository:
git clone https://github.com/sudectn/person-detection.git cd person-detection -
Install the required Python packages:
pip install -r requirements.txt
If using the extraction module, install additional dependencies:
pip install -r extraction/requirements.txt
Create a .env file in the root and the extraction directories with the following content:
CAMERA_USERNAME=your_username
CAMERA_PASSWORD=your_password
CAMERA_IP=your_camera_ip
CAMERA_PORT=554 # Default RTSP port
CAMERA_PATH=your_camera_path
ROBOFLOW_API_KEY=your_roboflow_api_key
The ROBOFLOW_API_KEY is required to access the detection model.
The system is divided into two main components: extract_frames.py and detect.py. These can be run separately in different terminals.
- Running Frame Extraction:
In one terminal, run:
python extract_frames.py
This will start capturing frames from the camera and save them to the image_frames directory.
- Running Person Detection:
In another terminal, run:
python detect.py
This will process the captured frames, detect the number of people, and update the live JSON files and daily reports.
- Live Count: The current number of people detected is saved in output/current_human_count.json.
- Daily Report: A JSON file (output/daily_human_count_report.json) containing the average number of people detected per day.
- Generated Graphs: Graphs showing the average human count per hour are saved in the output directory.
extract_frames.py: Captures frames from the RTSP stream.detect.py: Processes captured frames and detects the number of people.output/: Contains all output files, including JSON reports and graphs..env: Configuration file for camera credentials and settings, including the RoboFlow API key.requirements.txt: Lists the Python dependencies.extraction/requirements.txt: Lists additional dependencies for the extraction module.
- Ensure the RTSP camera is properly configured and accessible.
- Run
extract_frames.pyanddetect.pyin separate terminals. - The detection runs between 08:10 AM and 05:05 PM, and the report is generated at the end of the day.
- If you encounter issues with thread synchronization or camera feed access, check the logs for detailed error messages.