How reachzaki837/real-time-people-tracking-and-zone-based-occupancy-analytics works
Purpose and Execution Model
This is a notebook-driven computer-vision analytics pipeline for tracking people in recorded video and measuring occupancy by scene zone. There is no application server or package entry point: execution proceeds sequentially through notebooks/Phase1.ipynb to notebooks/Phase4.ipynb. Input and final video assets are externally hosted; committed artifacts primarily reside under outputs/analytics/.
1. Detection and Persistent Tracking
notebooks/Phase1.ipynb processes video frames with YOLOv8m, filters to the person class, and passes detections to DeepSORT. DeepSORT assigns persistent IDs using motion/IoU and appearance association, with settings intended to tolerate short occlusions (max_age=30, min_hits=3). This stage is the source of raw per-frame person tracks, materialized as outputs/analytics/raw_tracks.json.
2. Zone Modeling and Assignment
notebooks/Phase2.ipynb establishes four manually drawn, ordered polygons: Entrance, Checkout Area, Aisle, and Exit. Zone definitions are persisted in outputs/analytics/zones.json. For each tracked bounding box, the pipeline uses its bottom-center point as the standing-position proxy; if polygons overlap at a boundary, ordered first-match evaluation provides a single deterministic assignment. Enriched track events are written to outputs/analytics/tracks_with_zones.json.
3. Occupancy and Visit Analytics
notebooks/Phase3.ipynb transforms zone-assigned tracks into temporal metrics. Its main state boundary is between individual track observations and zone-level visit intervals: it counts current occupants per frame, identifies unique track IDs and entries per zone, derives dwell durations, and excludes visits shorter than 0.5 seconds. It also calculates peak occupancy and its timestamp.
4. Structured Output Contract
The pipeline’s principal machine-readable outputs are:
• outputs/analytics/frame_occupancy_log.csv: frame/time-series occupancy for all zones.
• outputs/analytics/zone_analytics.csv: tabular zone summary.
• outputs/analytics/zone_analytics.json: equivalent structured summary.
• outputs/analytics/tracks_with_zones.json: audit-level track-to-zone history.
These files form the handoff boundary for downstream reporting or graph/planning consumers without requiring video inference to be rerun.
5. Visualization and Final Rendering
notebooks/Phase4.ipynb produces presentation outputs from tracked and analyzed data, including annotated frames/video and summary visualizations. Existing diagnostic/report artifacts are kept alongside data in outputs/analytics/, including outputs/analytics/zone_analytics.json and outputs/analytics/frame_occupancy_log.csv. Final videos are described as external/generated output paths rather than being present in the supplied tree.
Runtime and External Dependencies
The runtime is Python/Jupyter, with dependencies declared in requirements.txt. Core services are local inference libraries rather than remote APIs: Ultralytics YOLOv8 for detection, deep_sort_realtime for tracking, OpenCV for video/frame handling, and NumPy/Pandas/SciPy/Matplotlib for data processing and visualization. Video inputs and model/video distribution rely on the linked Google Drive, making external asset availability a prerequisite for a clean rerun.
Main entry points: Phase4.ipynb Phase 4 notebook · Phase2.ipynb Phase 2 notebook · tracks_with_zones.json Zone-enriched tracks · Phase3.ipynb Phase 3 notebook
Components 17
Tracking
- Phase 1 notebook · Runs frame-by-frame detection and persistent tracking.
notebooks/Phase1.ipynb - YOLOv8m person detector · Filters detections to the person class.
- DeepSORT tracker · Associates detections into persistent IDs across short occlusions.
- Raw person tracks
outputs/analytics/raw_tracks.json
Zone assignment
- Phase 2 notebook · Assigns tracked people to ordered scene zones.
notebooks/Phase2.ipynb - Zone polygons · Ordered Entrance, Checkout Area, Aisle, and Exit polygons.
outputs/analytics/zones.json - Standing-point assignment · Uses bounding-box bottom center and first-match overlap resolution.
- Zone-enriched tracks · Track-to-zone history for downstream consumers.
outputs/analytics/tracks_with_zones.json
Occupancy analytics
- Phase 3 notebook · Converts zone observations into occupancy and visit metrics.
notebooks/Phase3.ipynb - Zone visit intervals · Derives entries and dwell; visits under 0.5 seconds are excluded.
- Frame occupancy log · Per-frame occupancy for every zone.
outputs/analytics/frame_occupancy_log.csv - Zone summary CSV · Tabular zone-level metrics.
outputs/analytics/zone_analytics.csv - Zone summary JSON · Structured zone-level metrics including peaks.
outputs/analytics/zone_analytics.json
Visualization
- Phase 4 notebook · Builds annotated media and summary visualizations.
notebooks/Phase4.ipynb - Annotated video and visuals · Final render paths are external or generated.
Other components
- Hosted video input · Google Drive availability is required for reruns.
- Python/Jupyter runtime · Uses OpenCV, NumPy, Pandas, SciPy, and Matplotlib alongside inference libraries.
requirements.txt
Connections 19
- Hosted video input → Phase 1 notebook: video frames
- Python/Jupyter runtime → Phase 1 notebook: runtime
- Phase 1 notebook → YOLOv8m person detector: frames
- YOLOv8m person detector → DeepSORT tracker: person detections
- DeepSORT tracker → Raw person tracks: persistent track IDs
- Raw person tracks → Phase 2 notebook: track observations
- Phase 2 notebook → Zone polygons: defines
- Zone polygons → Standing-point assignment: ordered polygons
- Phase 2 notebook → Standing-point assignment: applies
- Standing-point assignment → Zone-enriched tracks: zone events
- Zone-enriched tracks → Phase 3 notebook: observations
- Phase 3 notebook → Zone visit intervals: groups visits
- Phase 3 notebook → Frame occupancy log: writes
- Zone visit intervals → Zone summary CSV: summarizes
- Zone visit intervals → Zone summary JSON: summarizes
- Zone-enriched tracks → Phase 4 notebook: tracked overlays
- Frame occupancy log → Phase 4 notebook: occupancy charts
- Zone summary JSON → Phase 4 notebook: summary visuals
- Phase 4 notebook → Annotated video and visuals: renders