MQTT: laufende Nummer (total) ins Crossing-Event aufnehmen

Jedes crossing-Event enthaelt jetzt "total" = Gesamtzaehler-Stand zum
Zeitpunkt der Ueberquerung (= laufende Nummer des Fahrzeugs).
README-Payload-Beispiel ergaenzt.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-03 11:12:22 +02:00
parent 0b182e23fa
commit 3fa76e03ae
2 changed files with 7 additions and 4 deletions

8
app.py
View File

@@ -142,8 +142,9 @@ else:
print(f"[mqtt] init failed: {exc}", flush=True)
def publish_crossing(vehicle_type, track_id, source):
"""Crossing-Event auf {MQTT_TOPIC}/crossing (QoS 1, nicht retained)."""
def publish_crossing(vehicle_type, track_id, source, total):
"""Crossing-Event auf {MQTT_TOPIC}/crossing (QoS 1, nicht retained).
total = laufende Nummer dieses Fahrzeugs (= Gesamtzaehler nach dem Zaehlen)."""
if _mqtt is None:
return
payload = {
@@ -152,6 +153,7 @@ def publish_crossing(vehicle_type, track_id, source):
"source": source,
"type": vehicle_type,
"track_id": int(track_id),
"total": int(total),
"ts": datetime.now(LOCAL_TZ).isoformat(),
}
try:
@@ -424,7 +426,7 @@ def process_frame(frame, det_model, det_names, line_start, line_end, state, sour
recent_counts.append((center_x, center_y, frame_idx))
state["count"] += 1
types[label_name] += 1
publish_crossing(label_name, track_id, source)
publish_crossing(label_name, track_id, source, state["count"])
cv2.circle(frame, (center_x, center_y), 25, (0, 255, 0), 5)
dbg_counted += 1