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
This commit is contained in:
2026-01-20 00:51:06 +01:00
parent 432f0378bf
commit 1784214ee0

View File

@@ -125,23 +125,33 @@ class ZoneTracker:
# Check for zone transitions or first detection # Check for zone transitions or first detection
if face_id not in self.last_zone: 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.last_zone[face_id] = zone
self.tracked_faces[face_id] = (zone, current_time) 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: else:
# Face has been seen before - check for valid transition # Face has been seen before - check for valid transition
last_zone = self.last_zone[face_id] last_zone = self.last_zone[face_id]
# Only count if we have a clear zone assignment # Only count if we have a clear zone transition
# Entry: person appears in entry zone # Entry: person transitions to entry zone from non-entry zone
# Exit: person appears in exit zone # Exit: person transitions to exit zone from non-exit zone
if zone == 'entry' and last_zone != 'entry': if zone == 'entry' and last_zone != 'entry':
# Person entered # Person entered (transitioned to entry zone)
self.total_entered += 1 self.total_entered += 1
self.face_cooldowns[face_id] = current_time self.face_cooldowns[face_id] = current_time
self.last_zone[face_id] = zone self.last_zone[face_id] = zone
elif zone == 'exit' and last_zone != 'exit': elif zone == 'exit' and last_zone != 'exit':
# Person exited # Person exited (transitioned to exit zone)
self.total_exited += 1 self.total_exited += 1
self.face_cooldowns[face_id] = current_time self.face_cooldowns[face_id] = current_time
self.last_zone[face_id] = zone self.last_zone[face_id] = zone