Project Description:
This project implements a real-time person counting system using a custom-trained YOLO12 model. It detects and tracks people in a video feed and intelligently determines whether individuals are entering (IN) or exiting (OUT) a defined area, based on their movement across a virtual vertical line.
Using bounding box tracking IDs, the system compares the historical and current X-coordinates of detected individuals to calculate directionality. If a person crosses the line from left to right, they are counted as IN; if they move from right to left, they are counted as OUT. The cvzone library is used for clean visual annotations like drawing bounding boxes, center points, and displaying the real-time IN/OUT counters.
This application is highly relevant for:
-
Crowd management
-
Smart building automation
-
Retail store analytics
-
Security and surveillance
-
Event entry/exit monitoring
Key Features:
-
Custom-trained YOLO12 model for detecting people
-
Real-time tracking using unique object IDs
-
Directional logic for counting IN and OUT movements
-
Visualization of bounding boxes, centers, and motion path
-
Scalable for deployment with video streams or IP cameras
-
Lightweight model (nano variant) for edge device compatibility
Tech Stack:
-
Python 3.x – Core programming language
-
OpenCV – Frame capture, preprocessing, visualization
-
Ultralytics YOLO12 – Object detection and tracking
-
cvzone – UI overlay for bounding boxes and text
-
CUDA (optional) – GPU acceleration for real-time performance
-
NumPy – Array and numerical processing
-
Custom Trained YOLO12n Model – Lightweight, fast detection of people
Use Cases:
-
Smart Office Entry Monitoring
-
Retail Foot Traffic Analytics
-
Event Venue Entry/Exit Tracking
-
School/University Attendance Analysis
-
Public Transport Station Crowd Flow Management
-
Security & Surveillance Systems
Project Workflow:
-
Model Initialization
Load a custom YOLO12 Nano (yolo12n.pt) model trained for person detection. -
Video Input Handling
Read video frames from a file or webcam and resize for consistency. -
Detection & Tracking
Use YOLO12’strack()method with persistence to maintain object IDs across frames. -
Determine Center Coordinates
Calculate the center of each bounding box to monitor movement direction. -
IN/OUT Logic
Track history of X-center positions:-
If a person moves left → right across the vertical line:
IN -
If a person moves right → left:
OUT
-
-
Annotation & Display
-
Draw bounding boxes and center points
-
Display live IN and OUT counters using
cvzone.putTextRect()
-
-
Exit on ESC Key
Gracefully stop the program with the ESC key.
Conclusion:
This project delivers a lightweight, real-time solution for people counting using advanced object detection and tracking techniques. By combining a custom YOLO12 model with intuitive directional logic, the system provides valuable insights for applications ranging from crowd control to building automation. It is scalable, accurate, and suitable for deployment on low-resource edge devices.


Reviews
There are no reviews yet.