Files
parking_solution/wiki/concepts/zone-anpr-poc.md
T
julian 494c11ddbf
Build & push images / images (push) Successful in 4m55s
wiki: zone PoC shut down on park-lab; barrier on the staff remote only
The user's rule from 2026-11-22: the system is not ready to control the
barrier yet. Container zg2 is stopped, relays read off beforehand; notes how
to bring it back.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RZgP5oZdzvo92Eouc9eRv5
2026-11-22 18:34:12 +01:00

379 lines
22 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
type: concept
tags: [parking, vision, anpr, passage, relay, poc, park-lab]
sources: []
updated: 2026-11-22
---
# Zone ANPR PoC — field trials on park-lab
A vendor-neutral, NVR-style prototype of [[passage-confirmation]], run on park-lab against the real
lane, relays and barrier. Code: `poc/zone-anpr/` (`zone_anpr.py`, with its checks in `test_flow.py`
and the recorded drives in `recordings/`). It runs on park-lab as container `zg2`, with its page
on port 8094. Camera and relay credentials come from the environment only.
**Status (user, 2026-11-22):** the PoC has served its purpose. The flow and the relay rules work on
a live barrier; the plate and the detector do not hold on a wet night. Further hardening is
deferred to a later session, and the work list is on [[vision-hardening]].
**Shut down (user, 2026-11-22, evening):** container `zg2` is stopped, with all four relays read
off beforehand. The user's rule for now: *the barrier is operated only with the staff's remote
control; our system is not ready to control the barrier yet.*
- **Seeing the car:**
- the **low-res MJPEG stream** (1280×720), about 5 frames a second through YOLOX-Tiny on the Intel
iGPU;
- the same frames give the car's position against the drawn line: side A, on the line, or side B.
- **Reading the plate** ([[zone-anpr-plate-trials]]):
- **hi-res stills**, and the stream frames as a second source, CPU OCR, in the background;
- consensus of 3 votes and 75% agreement, every character ≥ 0.9;
- **no country or format rule** (user: the Albanian rule was "unacceptable").
- **Records:**
- `out/visits.jsonl` (the verdict per visit);
- `out/relays.jsonl` (every pulse, live or would-be);
- `out/reads.jsonl` (the plate per visit) and `out/reads-all.jsonl` (every read);
- `out/clips/` (every processed frame of a visit with its box, and the stills with their
reads).
## The flow (user, 2026-11-21)
> **Replaced (user, 2026-11-22).** The new flow is on [[passage-confirmation]], "Decided with the
> user (2026-11-22)", and is built: see [[#The 2026-11-22 build — new flow, relay rules, R2 live]].
> What follows is the 2026-11-21 flow, kept for the record of that night's trials.
1. **A car comes into a zone.** It counts when the detector is ≥ 0.4 sure and ≥ 20% of the car's
box lies in the zone. If the **other camera already owns the lane**, the car is ignored (see
[[#Shared lane]]). Otherwise a **visit** starts, and **R1 opens**.
2. **While the car is in the zone**, its side is noted on every frame. The plate is read on the
side, and nothing waits for it.
3. **The visit ends when the zone is free**:
- the car has been out of the zone for 1 s, or
- the car has not been seen at all for 3 s.
4. **The decision is made at once:**
| What the car did | Verdict | R2 |
|---|---|---|
| From A, ended fully on B | passed | nothing |
| Came toward the line or onto it, went back to A | **abandoned** | **close** |
| Stayed on A and never came closer | moving away | nothing |
| From B to A | other direction | nothing |
| Lost while on the line, or similar | unclear | nothing — the boom stays up |
| Started on B and stayed there | stayed beyond | nothing |
R2 fires only if R1 opened in the same visit.
**The user's rule for the close:** *"As soon as the zone is free and the crossing is abandoned we
fire R2."* How long a car stands in the lane does not matter. There is no dwell timer and no
window. This answers the dwell/window open question on [[passage-confirmation]].
**Trial settings, not the design:**
- R1 opens for **any** car. In the design it opens on a known plate or a ticket.
- R2 is a **dry run**: it is logged as "WOULD PULSE R2" and closes nothing, until the
preconditions on [[passage-confirmation]] are met.
- Relays are **disarmed by default** and arm for 30 min. A restart disarms them. The lane has
no wifi, so arming was done remotely (`POST /arm` on park-lab).
## The 2026-11-22 build — new flow, relay rules, R2 live
`zone_anpr.py` now implements the flow and the relay rules decided on [[passage-confirmation]]
("Decided with the user (2026-11-22)").
**Deployed to park-lab on 2026-11-22** (user: "Deploy"), container `zg2` restarted at 09:56 UTC:
- `"close_live": true` is set in its config, so R2 is live once the relays are armed;
- it came up **disarmed**, with both streams live and the board answering (all relays off);
- the 44 checks also pass inside the container;
- the previous file and config are kept beside it as `zone_anpr.py.bak-20261122-preflow` and
`config.json.bak-20261122-preclose`.
**`close_on_lost` is on, on park-lab (user, 2026-11-22).** After the user's point that the
barrier's own sensors cover the space under the boom, the config got `"close_on_lost": true` and
`zg2` was restarted at 10:00 UTC. A car the detector loses inside the zone now gives `abandoned`
and R2, like any other uncrossed open. The code's default stays off.
**The flow, as built:**
- A visit is one **busy period of the zone**. It starts as before, on a sure car in the zone, with
one R1.
- **Busy** means any vehicle in that camera's zone, at the low keep threshold (0.15), not only
the car being followed.
- A **crossing** is the followed car changing from fully on one side to fully on the other. The
last one replaces the one before. A car last seen on the line with its box at the picture's
edge counts as having left on that side, as before.
- Nothing is decided while the zone is busy. When it is free: last crossing A → B is `passed`;
anything else is `abandoned`, and R2 is asked for if R1 opened in that period.
- The line's `direction` is ignored: A → B is always in. The page has only "Swap A/B" left.
**Three defaults the user has not ruled on** (the "not settled" list on [[passage-confirmation]]):
- **A car that vanishes inside the zone gives `unclear` and no close.** The zone counts as free
only when the followed car was seen outside it. A car that drops out with its box at the
picture's edge does not count either. `"close_on_lost": true` in the config turns this off and
closes on a lost car too.
- **Busy looks at the camera's own zone only**, not at the other camera's.
- **A drive-out (B → A) is `abandoned` and fires R2**, as the flow says.
**The relay rules, as built:**
- One worker sends everything to the board, in order.
- Before a pulse it reads the status. Other relay off: fire. Other relay on: off command, read
again, and so on until it reads off. This is the same for open and close.
- A failed read or pulse is followed by an **online probe**: a TCP connect to the board's web
port (`relays.http_port`, default 80). Online: keep looping. Not online: the command is dropped
and the page shows **RELAY CONTROLLER OFFLINE**.
- **Immediately before every datagram** the command is checked again: still armed, not replaced
by a newer command, and still valid. A close is valid only while no visit is running, the zone
is not busy, and the last processed frame is under 1 s old. So an open never waits behind a
close that is still trying.
- While disarmed, or for a close with `close_live` off, **nothing** is sent: no pulse, no off
command, no read.
- Timing: 0.4 s for a reply, 0.1 s between tries (`relays.timeout_s`, `relays.retry_s`).
- The page has a "Read board" button (a status read, which moves nothing).
**Checked against the real board** (one status read from inside `zg2`, 2026-11-22): the reply was
`ffaa5a00000f`, session and command echoed, relays all off, in 42 ms. The web port 80 is open.
**Tests.** `poc/zone-anpr/test_flow.py` had 44 checks at this build, all passing, in three parts:
the flow on scripted boxes; the relay rules against a mock board, datagram by datagram; and a real
camera object wired to the real relay code and the mock board, armed with the close live. It
needs no camera, model or relay.
**Replay of the recorded night drive.** The boxes park-lab recorded for each visit
(`out/clips/*/frames.jsonl`) were fed through the new code, with the line that was in force
during the drive. Of the 23 entry visits, 21 have an old record to compare with, and the side
paths came out identical for all 21.
| Old verdict | Visits | New |
|---|---|---|
| passed | 7 | passed, no R2 |
| abandoned, the car followed out of the zone (17:02, 17:03, 17:36, 17:55, 17:56) | 5 | abandoned, R2 |
| abandoned, the recording ends with the car inside the zone (16:35, 16:37, 17:04, 17:05) | 4 | unclear, no R2 |
| other direction (16:34, 17:00, 17:54) | 3 | abandoned (B → A), R2 |
| stayed beyond | 1 | passed |
| moving away | 1 | unclear |
| cut off by a restart (17:33, 17:58) | 2 | abandoned and unclear |
- Of the nine entry drives the user confirmed live, the seven from 17:28 on come out as before,
except 17:54: the drive-out is now `abandoned` with R2, which is what the new flow says.
- The two confirmed abandonments at 16:35 and 16:37 become `unclear`, and so do 17:04 and 17:05.
In all four the old tracker lost the car while it was still in the zone:
- 16:35 and 16:37 have gaps of 6 s and 3 s between frames (the tracking loop was blocked);
- at 17:04 and 17:05 the reversing car was dropped with a quarter of its box still in the zone.
All four were recorded before the 17:20 restart. The three abandonments recorded after it
(17:36, 17:55, 17:56) were followed until the car was fully out of the zone, and they close.
**This is what the "no close on a lost car" default costs:** a turn-back the detector drops
inside the zone leaves the boom up.
- 16:35 is partly an artefact: the replay treats a gap between recorded frames as frames with no
car, where the real loop was standing still.
- A second replay ran the real detector on the saved frames (on the CPU, where park-lab uses the
iGPU). No visit was held open by other vehicles in the zone. Two short visits came out
differently because the boxes differ slightly between the two devices.
- The clips hold only frames in which the old tracker matched the car, so the replay cannot show
how often something else keeps the zone busy after a visit.
**Limits of this build:**
- The tracker is unchanged: one followed car, matched by overlap. A track that breaks or jumps to
another car now ends in `unclear`, or in a late decision, never in a close with a vehicle in
the zone.
- A second car that enters the zone before the first has left gets no open of its own.
- The exit camera has `relay_open` and no `relay_close`. While it owns the lane the entry camera
yields, so no close can come for that car.
- The lane lock, the plate stills and the disk items of [[zone-anpr-poc-review]] are untouched.
**R2 live (user, 2026-11-22: "this time we will try live firing of R2").** `close_live` is set on
park-lab; arming on the page is all that is left.
The three preconditions under "Still open" are **not met**: the interlock has not been checked
with a meter, the `DET`/`PHO` reversal has not been proven on the unit, and [[barrier-not-a-door]]
has not been revised. The user chose to run the trial anyway.
**Under the boom is the barrier's job (user, 2026-11-22):** *"The barrier always has radars or
infrared sensors that monitor the under the boom... If there is something the boom will not get
down whatever the relay commands."* So the PoC's "zone free" does not have to cover the space
under the boom, and nothing needs checking on the page before arming. This is the same split as
[[barrier-not-a-door]]: safety is in the barrier's firmware, the host only expresses intent. The
bench test of it on the park-lab unit ([[passage-confirmation]], test plan steps 2–3) has not
been run.
### Since the first build
The same day brought two more builds, both described on [[zone-anpr-plate-trials]]:
- **The plate build (deployed 11:15 UTC):** the stream frames as a second source beside the
stills, the stills kept with their reads, a new HTTP client for every still.
- **Two fixes after the night trial (deployed 16:54 UTC):**
- a side, and "outside the zone", count only after two looks in a row, and the leaving edge is
judged on the last box that agreed with the car's side. A stray last box had turned a
crossing into `abandoned`, and R2 had fired behind the car;
- a read does not vote when the picture is burnt out right beside the plate.
- **Checks now:** `test_flow.py` has 65. `replay_recordings.py` replays the 48 recorded entry
visits of both days from their recorded boxes: of the 21 where the driver said what he did, 20
are judged right with `close_on_lost` on (two of them would be `unclear` without it). The one
miss is the turn-back of 10:18 below, recorded while the zone still ended short of the picture's
edge.
- **park-lab has the file that is in the repository** (checked 2026-11-22), with `close_live` and
`close_on_lost` on in its config. The container is stopped; started again, it comes up disarmed.
## Live R2 trial (2026-11-22, AA927AU, UTC, daylight)
Relays armed at 10:00:50 with the close live and `close_on_lost` on. The table is what the PoC
logged. **The user confirmed that the boom came down at every abandonment** of the first run.
| Time | Camera | What the user did | Verdict | Relays |
|---|---|---|---|---|
| 10:02:45 | entry | drove through | passed (A → B at 10:02:54) | R1 |
| 10:03:15 | exit | the same car, driving on | abandoned (lost in the zone) | **R1 again**, no close possible |
| 10:03:42 | entry | abandoned the crossing | abandoned, zone free at 10:03:49 | R1, then **R2 sent** |
| 10:03:59 | entry | stood in the zone for 2 min 50 s, then abandoned | abandoned, zone free at 10:06:49 | R1, then **R2 sent** |
| 10:09:57 | entry | drove in | passed (A → B at 10:10:05) | R1 |
| 10:10:24 | exit | drove out | abandoned (lost in the zone) | R1, no close possible |
| 10:10:49 | entry | abandoned the crossing | abandoned, zone free at 10:10:57 | R1, then **R2 sent** |
- **All three closes went out live** and the board acknowledged them. The first two are the first
live R2 pulses.
- **The drive-out at 10:10:24 was handled by the exit camera alone.** It owned the lane, so the
entry camera yielded and saw no B → A crossing. The exit camera opened R1 and judged the pass
`abandoned`, which is the wrong word for it; it has no close relay, so nothing was sent.
- **Nothing was decided while the car stood in the zone** (10:03:59 to 10:06:49).
- **Every pulse was preceded by a status read**, and the other relay never read on.
- **The exit camera opened the barrier a second time for a car that had passed** (10:03:15,
twenty seconds after the crossing). The entry visit had ended, so the lane lock no longer held
it: finding 7 on [[zone-anpr-poc-review]]. The exit camera has no close relay, so that open
stayed until the next close.
### A turn-back judged as passed (10:18–10:22)
The user drove up, stood in front of the boom for three minutes and then reversed. The PoC
recorded `passed` at 10:21:08, and the boom stayed up.
- **The entry camera does not see the boom.** A car waiting in front of it stands mostly to the
right of the picture: from 10:18:14 only its rear was in view, and by 10:21:05 a strip between
x 0.91 and the edge.
- **That strip lay right of the line** (x 0.85–0.91), so the car read "on side B": a crossing
A → B.
- **The zone ends at x 0.94–0.95, short of the picture's edge.** Only a fifth of the strip was
inside it, so the zone read free a second later, and the visit was decided: passed.
- **The reversal was not seen.** With the entry visit over, the exit camera took the lane at
10:21:19 and fired R1. The entry camera ignored the car as it backed through its zone (10:22:00,
"lane busy with exit"). The exit camera judged `abandoned`, and it has no close relay.
Replayed on the recorded boxes with the **zone drawn to the picture's right edge**: the strip is
57% inside the zone, the visit stays busy, and then a car that drives on gives `passed`, and one
that reverses gives B → A, `abandoned` and R2. So the fix is the zone drawing, plus taking the
exit camera out of the lane (below).
### park-lab is the worst case (user, 2026-11-22)
The user's reading of the trial: park-lab is the hardest site there is. One lane serves entry and
exit, and the raised boom crosses the exit camera's picture.
- **Only park-lab has these problems:** the lane lock between two cameras, a drive-out that reads
as B → A on the entry line, and the exit camera opening for a car the entry camera should judge.
park-2 and park-buzi have two lanes and two barriers ([[passage-confirmation]]), so each camera
sees one direction.
- **Every site has these:** the camera has to see the car up to the boom, the zone has to reach
the picture's edge on that side, and a car the detector loses must be handled.
- **What the trial showed regardless of the site:** the flow and the read-then-fire relay rules
work on a live barrier, and the boom came down at every abandonment the entry camera judged.
## Night drive results (2026-11-21, AA927AU, UTC)
The user drove and confirmed each move live.
| Time | Camera | What the user did | Verdict | Right? |
|---|---|---|---|---|
| 16:35 | entry | stopped, reversed out | abandoned | ✅ |
| 16:37 | entry | stopped short of the line, reversed out | abandoned | ✅ |
| 17:28 | entry | drove through | passed | ✅ |
| 17:36 | entry | to the line, reversed | abandoned, R2 would close | ✅ |
| 17:52 | entry | drove through | passed | ✅ |
| 17:54 | entry | drove out toward the street | other direction | ✅ |
| 17:55 | entry | up to the line, reversed | abandoned, R2 would close | ✅ |
| 17:56 | entry | **nose over the line**, reversed | abandoned, R2 would close | ✅ |
| 17:59 | entry | stood ~50 s, then drove through | passed | ✅ |
| 17:32 | exit | drove out | moving away | ❌ |
| 17:53 | exit | reversed | abandoned | ✅ |
| 18:00 | exit | drove out | moving away | ❌ |
**Entry: every move judged right**, including the hard one (nose over the line, then back).
**Exit: not usable** (below).
## The back-and-forth — what failed and what replaced it
1. **R2 on "the car left the zone" (first try).** On the recordings it missed both turn-backs,
because a reversing car still overlaps the zone. It also produced a false close on a car waiting
outside the zone.
2. **R2 on retreat distance: 0.12 of the frame, held 2 s (second try).** It never fired on the
real drive. Once fully back on side A, a reversing car is in view for well under a second. The
user rejected waiting at all. That led to the flow above.
3. **The visit ended only when the car left the camera's view.** A car reversing down the street
was followed for minutes, so the verdict and R2 never came. Fix: the zone counts as **free**
after 1 s out of the zone.
4. **Plate stills blocked the tracking loop.** A hung still (3 s timeout, 11 times in 3 minutes
at night) froze the track, so a reversing car vanished between two frames. Fix: the plate read
runs in the background, at most one at a time per camera.
5. **The camera was being hammered.** Failed stills were retried on every frame. The camera
answered `503`, then `digest auth failed` about 5 times a second. That risks an account
lockout, which would cut the video stream too. Fix: back off 2, 4, 8 … up to 30 s after a
failure. **Root cause not found:** a still normally takes about 200 ms, and the night hangs are
unexplained.
**Likely cause, from [[zone-anpr-poc-review]] (finding 13):** `digest auth failed` is also what
the PoC's own HTTP client says once it has given up, which it does for good after six failed
stills in a row. It then sends no credentials, and the back-off does not cure it. Not yet
checked against the container log.
6. **Both cameras opened for the same car.** At 16:36 a car got an open from the entry camera
and another one 6 s later from the exit camera. Fix: a **lane lock**, see
[[#Shared lane]].
7. **A crop around the zone cut a close car in half.** The exit camera then saw no car at all.
Fix: detection runs on the whole frame. It costs the same, because the detector resizes anyway.
8. **Detection flickered in headlight glare.** A standing car scored 0.4–0.5 and dropped out for
3 s at a time. Each drop ended the visit, and the next sighting opened the barrier again. Fix:
a visit **starts** at ≥ 0.4 and **keeps** the car down to 0.15.
### Shared lane
park-lab is one lane for both directions ([[passage-confirmation]] "park-lab rig"), so every car
passes both cameras. The PoC lets **one camera own the lane at a time**. The other camera ignores
cars until the owner's visit has ended **and** its own zone has been empty once. Without that
second condition, the car just handled would start a new visit there, with a new open. On the
drive the far camera ignored the car every time, and no double open happened after the fix.
### Plates
Plate reading, what was measured about it, and the day and night trials of 2026-11-22 have their
own page: [[zone-anpr-plate-trials]]. In short:
- the plate reads only on a short stretch of the approach, and is not needed for the verdict;
- the hi-res still is the main reader, the stream frames a faster and weaker second source;
- on a wet night, 5 plates were decided in 11 entry visits, 2 of them wrong;
- a pass was judged abandoned that night, and two fixes followed (above, "Since the first build").
### The exit camera is out (user, 2026-11-21)
The user's verdict: *"Fuck the exit, it's flawed. The barrier interferes with the camera image when
it's open."*
- The boom swings through the exit camera's view when it rises. This was first seen in the
2026-11-19 recordings on [[passage-confirmation]].
- The exit line is also drawn off the cars' path.
- Exit verdicts were wrong on 2 of 3 drives.
- **On park-lab the entry camera alone judges the crossing in both directions:** it saw drive-ins
as A → B and drive-outs as "other direction". The exit camera is not used for crossing
verdicts. Whether it still opens R1 or reads plates for drive-outs is not yet decided.
## Still open
Deferred by the user on 2026-11-22. The work list, with the evidence for each item, is on
[[vision-hardening]]. The points that are the user's to rule on:
- **A car the detector loses inside the zone:** no close (the code's default) or a close
(`close_on_lost`, on at park-lab).
- **The exit camera on park-lab:** it still opens R1 and cannot close.
- **R1 on known plates only,** which is the real design. The PoC opens for any car.
Before R2 is used anywhere else, the preconditions on [[passage-confirmation]] still stand: the
interlock checked with a meter, the `DET`/`PHO` reversal proven on the unit
([[zkteco-cmp200-barrier]]), and [[barrier-not-a-door]] revised. The Dingtian "Mutually
Exclusive" mode does not replace the wiring.