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