fix counter bug

This commit is contained in:
Alberto-Audrix committed 2026-08-05 09:28:27 +07:00
1 parent cb0b8ac1d9
commit 41c4a558b1
2 files changed
+33 -9

No files matched your search

+13 -6
View File
@@ -1215,8 +1215,9 @@ def run():
frames_since_infer = 0
video_writer = None
crossing_times = deque()
counter_in = 0
counter_out = 0
# Overlay shows daily store totals (resume-safe, resets on counting-day change).
counter_in = store.current_count_in
counter_out = store.current_count_out
last_snapshot_cleanup = 0.0
counting_active = True
@@ -1495,13 +1496,17 @@ def run():
recent.append((frame_idx, cx))
st["counted"] = True
_, _, counted = store.record_object_crossing(tid, direction)
counter_in = store.current_count_in
counter_out = store.current_count_out
if not counted:
# Dedup in the store rejected this event; skip overlay/CSV.
object_tracked[tid] = (cx, cy, mono)
continue
if direction == "in":
counter_in += 1
count_in_pulse = COUNT_PULSE_FRAMES
else:
counter_out += 1
count_out_pulse = COUNT_PULSE_FRAMES
store.record_object_crossing(tid, direction)
if cross_logger:
cross_logger.write_row(
[
@@ -1550,7 +1555,9 @@ def run():
if object_crossed_frame:
line_pulse = LINE_PULSE_FRAMES
display_total = store.display_total()
# Keep overlay aligned with daily store (also resets after cutoff).
counter_in = store.current_count_in
counter_out = store.current_count_out
while crossing_times and mono - crossing_times[0] > RATE_WINDOW_SEC:
crossing_times.popleft()
rate = (len(crossing_times) / RATE_WINDOW_SEC * 60) if crossing_times else 0.0