This project provides a complete web-based system to detect and count people crossing a custom-defined line in a video using YOLOv8 and ByteTrack. It features a Streamlit frontend and a Python backend with logging and video annotation.
- 🖼️ Upload video and draw counting line on the first frame
- 🧠 YOLOv8 + ByteTrack to detect & track people (class_id = 0)
- 🧮 Count people who cross the defined line (with deduplication)
- 📦 Output annotated video with bounding boxes, tracker IDs, and line overlay
- 📊 Export all detection logs to Excel (bbox, class, confidence, frame, tracker_id)
- 📉 Live frame-by-frame processing progress in Streamlit
| Layer | Technology |
|---|---|
| Object Detection | YOLOv8 (Ultralytics) |
| Tracking | ByteTrack |
| UI | Streamlit |
| Drawing | streamlit-drawable-canvas |
| Frame Handling | OpenCV |
| Annotation | Supervision |
| Logging | Excel export (via pandas) |
project/
├── app.py # Main Streamlit UI
├── draw_line.py # Drawing canvas logic
├── yolov8_track_count.py # Core detection & counting logic
├── output/ # All generated outputs
│ ├── <video_name>_result.mp4
│ ├── <video_name>_line_coords.json
│ └── <video_name>_detections.xlsx
-
Launch the Streamlit app:
streamlit run app.py
-
Upload a video (MP4 or AVI format)
-
Draw a line across the first frame (this is the crossing line)
-
Run detection – people crossing the line will be counted
-
Download Excel file to view all detections and bounding boxes
| Column | Description |
|---|---|
| frame | Frame number |
| tracker_id | Unique person tracker ID |
| class_id | Object class (0 = person) |
| conf | Detection confidence score |
| x1, y1, x2, y2 | Bounding box coordinates |
- Only class_id = 0 (person) is counted
- The same person is counted only once when crossing the line
- All logic assumes one custom-drawn line per video
- If using older versions of
supervision, the direction-based counting is disabled
pip install -r requirements.txtRequirements (manually ensure):
ultralyticsopencv-pythonpandassupervision >= 0.6.0(for direction-aware line zones)streamlitstreamlit-drawable-canvasopenpyxl(for Excel export)
- Support multiple lines/zones
- Add filtering (e.g., count only adults, helmets, etc.)
- Heatmap visualization from detection logs
Developed by LTA Data Scientists Team