dd2dd53d7e
- zone-anpr-poc: H.264 instead of MJPEG (load, delay, a car in the zone, staff traffic, bad weather); the relay-less test copy is left running - event-driven-refactor (new): the user's decisions of 2026-11-23, what is not decided, what they touch in today's code; waits for the user's guidelines - passage-confirmation: the 2026-11-19 phase order superseded; where the video work lives - vision-hardening, zone-anpr-poc-review: on-screen label read as a plate (moved by the user), day-time oversized box, still pause carried over - pointers on vision-service, camera-live-view, lane-presence-and-anpr-entry, dingtian-vs-mqtt, entry gates, standing decisions, open questions, overview, index Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RZgP5oZdzvo92Eouc9eRv5
557 lines
34 KiB
Markdown
557 lines
34 KiB
Markdown
---
|
||
type: concept
|
||
tags: [parking, vision, anpr, passage, relay, poc, park-lab]
|
||
sources: []
|
||
updated: 2026-11-23
|
||
---
|
||
|
||
# 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.*
|
||
|
||
**Back for one test (user, 2026-11-23):** a copy with **no relay board configured** (container
|
||
`zg-h264`) runs on H.264 sub-streams, to see what decoding costs. `zg2` stays stopped. See
|
||
"H.264 instead of MJPEG" below. **Left running (user, 2026-11-23):** in this state it is
|
||
harmless, no relay is armed or configured. The cameras' sub-streams stay on H.264 with it.
|
||
|
||
- **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.
|
||
|
||
## H.264 instead of MJPEG (2026-11-23)
|
||
|
||
**Why (user).** The server should hold no video or image work. MJPEG let it pass frames along
|
||
undecoded, which locks the system to cameras that offer MJPEG. A camera that streams only H.264
|
||
or H.265 has to be decoded somewhere, and that place is the vision side. The test: switch the
|
||
sub-streams to H.264, decode them in the PoC, show a live picture on its page, and watch the
|
||
booth PC's load.
|
||
|
||
**Set-up.**
|
||
|
||
- Container `zg-h264` on park-lab: the same image and code, `config-h264test.json`, records in
|
||
`out-h264test/`, page on port 8094. Its config names **no relay board** and it has no relay
|
||
password, so its arm button has nothing to send to. Restart policy `no`.
|
||
- The PoC gained a **live picture** for the page (`/live/<camera>.mjpg`): every decoded frame is
|
||
re-encoded as a JPEG once, for all viewers, and only while somebody watches. Before, the page
|
||
fetched a still every 700 ms. The metrics gained the codec, the network intake, the viewers and
|
||
the time from connecting to the first picture.
|
||
- Decoding is in software (FFmpeg inside OpenCV 4.13), RTSP over TCP, with FFmpeg's `nobuffer`
|
||
and `low_delay` set. The detector stays on the iGPU.
|
||
- **Camera change:** channel 102 on both cameras went from MJPEG to **H.264** (Main profile), with
|
||
a keyframe about every second (GOP 12 on the entry camera, 20 on the exit camera). Resolution,
|
||
frame rate and the 1024 kbps VBR cap were left as they were. The settings from before are saved
|
||
on park-lab as `~/zone-anpr-gpu/h264test/cam6-102-before.xml` and `cam7-102-before.xml`; a PUT
|
||
of those files puts MJPEG back.
|
||
|
||
**Measured** (21 ten-second windows each, empty lane, one viewer on each camera's live picture):
|
||
|
||
| | MJPEG | H.264 |
|
||
|---|---|---|
|
||
| Process CPU, of 6 cores | 0.40 | 0.41 |
|
||
| Host busy | 8.0% | 7.8% |
|
||
| Memory | 309 MB | 372 MB |
|
||
| Network intake | 15.2 Mbps | 1.85 Mbps |
|
||
| Frames in and decoded a second (entry + exit) | 12.5 + 20 | 12.5 + 20 |
|
||
| Live frames a second to the viewer | 12.5 + 20 | 12.5 + 20 |
|
||
| Detector, ms a look | 21 | 32 |
|
||
| First picture after connecting (entry, exit), one connect each | 1.8 s, 2.9 s | 3.6 s, 2.6 s |
|
||
|
||
- **The codec makes no difference to the CPU.** The network intake falls to an eighth.
|
||
- The earlier figure of 6–7% CPU was also taken with every MJPEG frame decoded (mode `stream`),
|
||
not only the frames looked at.
|
||
- Eight H.264 decode errors were logged in the second the exit stream first connected
|
||
(06:47:55 UTC), and none in the five minutes after. No stream loss after the switch.
|
||
- **The user, watching the page during the MJPEG run (2026-11-23):** "7%–8% CPU load. Not
|
||
bad." The user has not yet commented on the H.264 numbers.
|
||
|
||
**Delay from the camera to the live picture** (2026-11-23). Measured as on [[camera-live-view]]:
|
||
the camera's printed clock against the arrival of the live picture's JPEG, here at a viewer on
|
||
the booth PC itself, with each camera's clock bracketed over ISAPI to ±6–14 ms. 65–75 second
|
||
flips per camera; the minute flip agrees, so the figures are not off by whole seconds.
|
||
|
||
| | Entry (12.5 fps) | Exit (20 fps) |
|
||
|---|---|---|
|
||
| MJPEG straight from the camera (2026-11-17) | 0.09–0.10 s | 0.09–0.10 s |
|
||
| H.264, decoder on its default threads | 0.51–0.61 s | 0.39–0.43 s |
|
||
| H.264, **one decode thread** | 0.12–0.24 s | 0.18 s |
|
||
|
||
- **Cause of the first figure:** FFmpeg decodes H.264 on several threads by default, and each
|
||
extra thread holds one more frame back. On the 6-core booth PC that is 5 frames: 0.40 s at
|
||
12.5 fps, 0.25 s at 20 fps, which is the drop measured. The `low_delay` capture option did
|
||
not prevent it.
|
||
- **Fix in the PoC:** config key `decode_threads` (passed to OpenCV as `CAP_PROP_N_THREADS`);
|
||
the test copy runs with 1.
|
||
- With one decode thread and nobody watching the process used 0.27 cores and 328 MB, with no
|
||
decode error and the detector still at 5 looks a second.
|
||
- What is left, about 0.1 s over MJPEG, covers the camera's H.264 encoder, the decode and the
|
||
re-encode. A browser elsewhere adds its network and drawing time, which this does not include.
|
||
|
||
**The user's readings on the booth PC (2026-11-23, H.264, default decode threads):**
|
||
|
||
| | CPU | Download | Upload |
|
||
|---|---|---|---|
|
||
| Watching both pictures | 7–8% | 1.3 Mibps | 19.5 Mibps |
|
||
| Nobody watching | 5–6% | 1.1 Mibps | 400 Kibps |
|
||
|
||
Memory is steady either way. The upload is the live picture going to the browser as JPEGs
|
||
(about 107 KB a frame from the entry camera and 63–67 KB from the exit camera).
|
||
|
||
**A car in the zone** (2026-11-23, 07:32–07:33 UTC, AA927AU, H.264 with one decode thread; the
|
||
barrier was not driven, the relay lines are "would pulse" records). Read from the frames; the
|
||
user has not yet said what was driven.
|
||
|
||
| Start (UTC) | What the frames show | Verdict | Plate |
|
||
|---|---|---|---|
|
||
| 07:32:23 | drove up, stood 17 s short of the line, backed out | `abandoned`, would close | `AA927AU` decided after 0.34 s: 2 video frames and 1 still |
|
||
| 07:32:54 | drove up further, stood 4 s, backed out | `abandoned`, would close | undecided: `AA927AU` 2 votes, `HUIJE` 1 vote |
|
||
|
||
- **The flow judged both as the frames show them.** The followed car was matched in 5.0 looks a
|
||
second in both visits.
|
||
- **Video frames read the plate as well as before.** With the plate 65–90 px wide, 4 of 4 reads
|
||
were right and sure, the same as in the MJPEG day trial of 2026-11-22 (4 of 4). The sample is
|
||
small.
|
||
- **The camera's on-screen label was read as a plate.** In the second visit the car stood with
|
||
its bumper under the label "Hyrje" that the camera prints into the picture, and its own plate
|
||
was edge-on. 21 video frames and 3 stills then read the label (`HUIJE`, `HU1JE`, `HUIJB`), and
|
||
one still was sure enough (0.986) to vote. This is not an H.264 effect: 30 such reads are in
|
||
the records of 2026-11-20 to 22, none of them sure enough to vote until today. Now on
|
||
[[vision-hardening]]. The user moved both labels to the top-right corner the same day.
|
||
- **Load with the car in the zone:** 0.36–0.42 cores while it stood, and 0.84 cores (15% of the
|
||
host) for the ten seconds with 33 plate reads; memory rose from 329 to 512 MB and fell back to
|
||
441 MB. The detector kept 5 looks a second at 25–31 ms.
|
||
- **Two stills timed out** in the second visit (2 s and 4 s pauses), as on the earlier days. No
|
||
decode error and no stream loss.
|
||
|
||
**Staff traffic** (2026-11-23, 07:52–09:11 UTC, the same test copy). The user: the staff drove,
|
||
not the user. Nobody said what each vehicle did, so the column "What the frames show" is a
|
||
reading of the recorded frames, and these visits are not part of the scored set in
|
||
`recordings/`. The barrier was not driven: all 13 rows in `relays.jsonl` have `sent: false`.
|
||
|
||
| Start (UTC) | Camera | What the frames show | Seen | Verdict | Plate |
|
||
|---|---|---|---|---|---|
|
||
| 07:52:53 | entry | a dark car drives in without stopping | 0.6 s | `passed` | none: 1 video read at 52 px (weak), the one still timed out |
|
||
| 08:00:43 | exit | the same model of car, front to the camera, behind a blur that covers most of the picture | 0.4 s | `abandoned`, lost | undecided: `AB242TD`, 1 vote from a still (0.96); 3 video reads at 49–55 px |
|
||
| 08:28:36 | exit | a dark SUV moves out of sight behind a grey mass that fills the left half of the picture | 1.2 s | `abandoned`, lost | none: 3 stills, no plate found |
|
||
| 08:33:29 | entry | a black SUV stands 20 s short of the line, then five people push it through, rear first | 26.8 s | `passed` | none: 11 stills, no plate found; 4 stills timed out |
|
||
| 08:53:16 | entry | a white off-roader drives in without stopping | 2.2 s | `passed` | none: 2 video reads at 41–44 px (weak), 1 still read weak (0.61) with the plate at the crop's edge, 1 still timed out |
|
||
| 09:01:24 | exit | the white off-roader's rear at the edge of the grey mass | 0.2 s | `abandoned` | none |
|
||
| 09:09:44 | exit | a dark hatchback stands 62 s in the zone, then moves back, away from the camera | 63.3 s | `abandoned` | none: 91 video tries, 5 weak reads; 2 weak still reads |
|
||
| 09:11:04 | exit | not looked at | 0.6 s | `abandoned`, lost | none |
|
||
|
||
- **Bad weather (user, 2026-11-23).** The cameras are outdoors and the weather cannot be
|
||
fixed. The lane is wet in every clip of that morning. The soft plates and the blur in the exit
|
||
camera's picture have to be read with that in mind; how much of them is the weather was not
|
||
separated from the rest.
|
||
- **Entry camera: 3 of 3 `passed`,** which is what the frames show, and no close would have gone
|
||
out. The pushed car was followed for 27 s at 5 looks a second with five people around it.
|
||
- **Exit camera: not scored.** It is out for verdicts (see "The exit camera is
|
||
out"). Each of its five visits would have pulsed the open relay.
|
||
- **No plate was decided in eight visits. The records do not show that H.264 is the cause, and
|
||
they do not rule it out:**
|
||
- in the two drive-ins the plate was 41–52 px wide in the video frames at the moment the visit
|
||
started, under the 64 px gate, so those reads could not vote on MJPEG either (item 4 on
|
||
[[vision-hardening]]: the plate has to be read before the visit starts);
|
||
- on the MJPEG days (2026-11-21 and 22) the entry camera's video reads under 65 px were sure
|
||
(≥ 0.90) in 10 of 120; today in 3 of 17. At 65–90 px: 6 of 36 on MJPEG, 4 of 4 today, all
|
||
four from the user's own drive;
|
||
- the exit camera's five video reads at 82–88 px (09:10:46–47) scored 0.11–0.21. In those
|
||
frames the plate is too soft to read by eye. On the MJPEG days the exit camera's reads at
|
||
that width were sure in 2 of 7.
|
||
- The sample is too thin for a comparison. A drive with a known plate is still needed.
|
||
- **The blur and the grey mass in the exit camera's picture are not decoding faults.** The blur
|
||
of 08:00 is in the hi-res still as well, which does not come from the H.264 stream. What they
|
||
are was not established from the frames ([[vision-hardening]] records that the boom crosses
|
||
this camera's picture).
|
||
- **A vehicle's box reached the moved label, and it was not read.** The off-roader's box rose to
|
||
y = 37 of 720 at the right edge (08:53:19), with the label "Hyrje" inside it. No read of the
|
||
label is in the records of any of the eight visits.
|
||
- **Still timeouts on the entry camera:** 8 in 28 tries today (the user's drive included),
|
||
against 9 in 67 on 2026-11-22 by day. Cause not known. One on the exit camera.
|
||
- **The pause carried over to the next car** (finding 14 on [[zone-anpr-poc-review]], seen
|
||
live): the fail count is reset only by a still that succeeds, so the timeout at 07:52:54
|
||
drew an 8 s pause after the two of 07:32–07:33, twenty minutes earlier.
|
||
- **The stream held:** 12.5 and 20 frames a second in every ten-second window from 07:34 to
|
||
09:14 UTC, no decode error, no reconnect.
|
||
- **Load:** 0.27 cores with an empty lane; 0.77–0.90 cores (13–15% of the host) in the windows
|
||
with a standing vehicle being read. Memory went from 329 to 497 MB over the morning in steps,
|
||
one at each visit. The MJPEG run of 2026-11-22 did the same (296 MB after a start, 448–535 MB
|
||
after visits, peaks of 0.9–1.05 cores), so neither is an H.264 effect.
|
||
|
||
**Not measured.**
|
||
|
||
- Plate reading from H.264 frames at night, and by day with a known plate on a car that drives
|
||
through (the staff's drive-ins gave no usable comparison). The user (2026-11-23): this will be
|
||
handled as work of its own; it does not hold up moving the video work to the vision side
|
||
([[event-driven-refactor]]).
|
||
- Why the detector's time rose from 21 to about 30 ms a look. It still made its 5 looks a second
|
||
on both cameras in every run.
|
||
|
||
**Side effect, as long as 102 stays on H.264.** The parking server's booth camera tiles
|
||
([[camera-live-view]]) take MJPEG only (`packages/devices/src/drivers/rtsp-mjpeg.ts` refuses any
|
||
other codec), so they show no live video for these two cameras, on park-lab and on the dev
|
||
machine.
|
||
|
||
## 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.
|