A sophisticated computer vision system that combines person detection, face recognition, and depth-based door detection to track people entering and exiting through doorways.
-
Person Detection & Tracking
- Uses YOLO (You Only Look Once) for real-time person detection
- Tracks individuals across frames using IoU (Intersection over Union)
- Maintains persistent person IDs for continuous tracking
-
Face Recognition
- Leverages InsightFace for robust face detection and recognition
- Matches detected faces against a pre-loaded database
- Associates faces with detected persons using spatial overlap
-
Door Detection
- Uses DepthAnything V2 model for depth estimation
- Detects door frames using depth map analysis
- Supports both fully visible and partially visible door frames
-
Entry/Exit Monitoring
- Tracks people's positions relative to detected doors
- Uses depth comparison to determine if someone is entering or exiting
- Logs all entry/exit events with confidence scores
-
AsyncDepthProcessor
- Handles depth estimation asynchronously
- Uses a worker thread to prevent blocking the main loop
- Maintains frame queues for smooth processing
-
PersonTracker
- Manages person state tracking
- Records entry/exit events
- Maintains history of person movements
- Logs activities to CSV file
-
Face Management
- Loads face database from images
- Performs real-time face matching
- Associates faces with detected persons
-
EnhancedFaceAnalysis
- Custom wrapper around InsightFace's FaceAnalysis
- Adds optimized face processing method without modifying the library
- Improves performance by reusing detection results
associate_face_person(): Links detected faces with person bounding boxesdetect_door_from_depth(): Processes depth maps to identify door framesvisualize_depth_heatmap(): Creates visual representation of depth dataIOU_tracker(): Tracks person identities between framesmatch_face(): Performs face recognition against database
- Frame Capture → Person Detection → Face Detection
- Face-Person Association → Identity Matching
- Door Detection → Depth Analysis
- State Tracking → Event Logging
- OpenCV (cv2)
- PyTorch
- Ultralytics YOLO
- InsightFace
- NumPy
- DepthAnything V2
- YOLO model (
yolo11n.pt) - Depth estimation models:
depth_anything_v2_vitl.pthdepth_anything_v2_vits.pth
project/
├── faces/ # Face database images
├── yolo11n.pt
├── depth_anything_v2_vits.pth
├── depth_anything_v2_vitl.pth
├── face_analysis_wrapper.py
└── person_tracking.csv
person_tracking.csv: Entry/exit event log with timestamps- Timestamp
- Person Identity
- Action (Entered/Exited)
- Confidence Score
- Async depth processing to maintain frame rate
- IoU-based tracking for performance
- Configurable frame skip for face recognition
- GPU acceleration support for all deep learning models
-
Initialization
- Loads all required models
- Initializes tracking systems
- Performs initial door detection
-
Main Loop
- Captures frame
- Detects persons and faces
- Updates tracking information
- Monitors door activity
- Updates display and logs
-
State Management
- Tracks person locations
- Manages identity associations
- Handles disappearances
- Updates entry/exit states
-
Visualization
- Bounding boxes for persons and faces
- Association lines
- Identity labels with confidence
- Inside/Outside status
- FPS counter
- Graceful handling of frame capture failures
- Model initialization timeout protection
- Recovery from tracking losses
- Robust face recognition matching
- Place face images in
faces/directory - Ensure all model files are present
- Run the main script:
python live.py- System will automatically:
- Detect doors in the first frame
- Begin tracking people
- Log all entry/exit events