This project implements a real-time head detection and people counting system using YOLOv8 and OpenCV. The system detects and tracks individuals in a video stream, specifically focusing on identifying and counting people exiting a room.
- Real-time head detection using YOLOv8.
- People tracking using object ID assignment.
- Exit counting mechanism to track people leaving the frame.
- Live video feed processing from a webcam.
- Bounding box drawing for visual feedback.
Ensure you have the following dependencies installed:
pip install opencv-python torch numpy ultralyticsmain.py: Main script for real-time detection and tracking.models/yolov8n.pt: Pre-trained YOLOv8 model (must be downloaded separately).
- Load YOLOv8 Model: The script initializes a YOLOv8 model trained for person detection.
- Frame Processing: Each frame from the webcam is processed to detect people and track their movement.
- Head Extraction: Bounding boxes are adjusted to focus on head regions.
- Tracking & Counting: IDs are assigned to individuals, and the system tracks when they exit the frame.
- Display Output: The processed frame is displayed with bounding boxes and exit count.
Run the script using:
python main.pyPress q to exit the application.
- Ensure that
models/yolov8n.ptis placed in the correct directory. - Adjust confidence threshold in
model.track(frame, conf=0.6)if needed.
- Enhance tracking accuracy with motion prediction.
- Improve head region extraction logic.
- Implement database logging for long-term analysis.
This project is for educational purposes. Modify and distribute as needed.