poc(zone-anpr): passage-confirmation prototype run on park-lab
A standalone prototype of passage confirmation, tried on park-lab against the real lane, relays and barrier (wiki: concepts/zone-anpr-poc.md). - zone_anpr.py: vehicle detection on the camera stream, a drawn zone and crossing line, and the zone flow: nothing is decided while the zone is busy; when it is free the last crossing decides (A -> B passed, otherwise abandoned -> close relay). Relays follow read-then-fire with an online probe and a check before every datagram; disarmed by default. Plates are read from hi-res stills and stream frames into one consensus. - test_flow.py: 65 offline checks of the flow, the relay rules against a mock board, and the plate reads. No camera, model or relay needed. - recordings/ + replay_recordings.py: the followed car's boxes for 48 real entry visits of 2026-11-21/22, replayed through the judging code. - trial_report.py: per-visit report of a drive, run on park-lab. The detector model, local config and outputs are not committed (.gitignore). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RZgP5oZdzvo92Eouc9eRv5
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Minimal ONVIF client: the vendor-neutral way to ask a camera for its snapshot URL.
|
||||
Only what the PoC needs: GetProfiles + GetSnapshotUri, WS-UsernameToken digest auth."""
|
||||
import base64, hashlib, os, re, urllib.request
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def _call(host, user, pw, path, body):
|
||||
nonce = os.urandom(16)
|
||||
created = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
digest = base64.b64encode(hashlib.sha1(nonce + created.encode() + pw.encode()).digest()).decode()
|
||||
env = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
|
||||
<s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
||||
<UsernameToken><Username>{user}</Username>
|
||||
<Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">{digest}</Password>
|
||||
<Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">{base64.b64encode(nonce).decode()}</Nonce>
|
||||
<Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">{created}</Created>
|
||||
</UsernameToken></Security></s:Header><s:Body>{body}</s:Body></s:Envelope>"""
|
||||
req = urllib.request.Request(f"http://{host}{path}", env.encode(),
|
||||
{"Content-Type": "application/soap+xml; charset=utf-8"})
|
||||
return urllib.request.urlopen(req, timeout=10).read().decode()
|
||||
|
||||
|
||||
def profiles(host, user, pw):
|
||||
"""[(token, width, height)] in the camera's order (main stream first, as a rule)."""
|
||||
x = _call(host, user, pw, "/onvif/media_service", "<trt:GetProfiles/>")
|
||||
out = []
|
||||
for p in re.findall(r"<trt:Profiles\b(.*?)</trt:Profiles>", x, re.S):
|
||||
tok = re.search(r'token="([^"]+)"', p).group(1)
|
||||
w = re.search(r"<tt:Width>(\d+)", p)
|
||||
h = re.search(r"<tt:Height>(\d+)", p)
|
||||
out.append((tok, int(w.group(1)) if w else 0, int(h.group(1)) if h else 0))
|
||||
return out
|
||||
|
||||
|
||||
def snapshot_uri(host, user, pw, token):
|
||||
x = _call(host, user, pw, "/onvif/media_service",
|
||||
f"<trt:GetSnapshotUri><trt:ProfileToken>{token}</trt:ProfileToken></trt:GetSnapshotUri>")
|
||||
return re.search(r"<tt:Uri>([^<]+)</tt:Uri>", x).group(1).replace("&", "&")
|
||||
Reference in New Issue
Block a user