From 1784214ee07c75c1593a2be13935335d3e8f33f6 Mon Sep 17 00:00:00 2001 From: eroncero Date: Tue, 20 Jan 2026 00:51:06 +0100 Subject: [PATCH] feat: enhance zone tracking logic for entry/exit detection - Update zone transition logic to count first detections in entry and exit zones - Refine conditions for counting entries and exits based on zone transitions - Improve comments for clarity on zone assignment and transitions --- zone_tracker.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/zone_tracker.py b/zone_tracker.py index 78fae7a..6eb88a9 100644 --- a/zone_tracker.py +++ b/zone_tracker.py @@ -125,23 +125,33 @@ class ZoneTracker: # Check for zone transitions or first detection if face_id not in self.last_zone: - # First time seeing this face - mark the zone + # First time seeing this face - count if in entry/exit zone self.last_zone[face_id] = zone self.tracked_faces[face_id] = (zone, current_time) + + # Count on first detection in entry/exit zones + if zone == 'entry': + # Person entered (first detected in entry zone) + self.total_entered += 1 + self.face_cooldowns[face_id] = current_time + elif zone == 'exit': + # Person exited (first detected in exit zone) + self.total_exited += 1 + self.face_cooldowns[face_id] = current_time else: # Face has been seen before - check for valid transition last_zone = self.last_zone[face_id] - # Only count if we have a clear zone assignment - # Entry: person appears in entry zone - # Exit: person appears in exit zone + # Only count if we have a clear zone transition + # Entry: person transitions to entry zone from non-entry zone + # Exit: person transitions to exit zone from non-exit zone if zone == 'entry' and last_zone != 'entry': - # Person entered + # Person entered (transitioned to entry zone) self.total_entered += 1 self.face_cooldowns[face_id] = current_time self.last_zone[face_id] = zone elif zone == 'exit' and last_zone != 'exit': - # Person exited + # Person exited (transitioned to exit zone) self.total_exited += 1 self.face_cooldowns[face_id] = current_time self.last_zone[face_id] = zone