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:
8
app.py
8
app.py
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user