--- type: concept tags: [parking, vision, barrier, lane, ledger, safety, design] sources: [] updated: 2026-11-23 status: open --- # Passage confirmation — did the car actually cross? (design, 2026-10-24) **Problem (user, 2026-10-24).** A motion push opens the barrier and signs the entry/exit. If the driver changes their mind and reverses out, the ledger holds a false entry, and — because the barrier operator at the sites closes **only when its sensor/radar is tripped by a passage** — the boom stays up until the next car trips it. That next car enters with no ticket, no read, no ledger row. So an abandoned entry is both a wrong row and a free pass. Related: the FIFO stale-occurrence problem seen on AB694XU the same day (an exit closes the oldest open occurrence; one double read leaves a subscriber permanently one stay behind). **Constraint (user).** The cameras are the cheap Hikvision DS-2CD1043G2-LIU: motion push with a vehicle target, a sub-stream, and no line-crossing / smart events. The booth PC does the thinking. Cameras are sensors; compute is ours. The Dahua bench unit has tripwire (`CrossLineDetection`) but that is not the fleet camera. ## Design 1. **Frames: the RTSP sub-stream, not ISAPI stills.** Keep one RTSP session open per camera permanently (avoids the keyframe start-up gap of 1–2 s; set the sub-stream I-frame interval to ≤ 1 s). Decode in the vision service (OpenCV 4.13 with FFmpeg is already in the container; no `ffmpeg` binary needed). The still-pull loop in `anpr-entry.ts` is replaced by this — it also removes the single-threaded picture-endpoint collisions (503s). *Latency (user asked 2026-10-24):* RTSP itself adds nothing meaningful; the delay is the camera's encoder (~100–300 ms) plus whatever the decoder buffers. Open the stream with a minimal buffer (`CAP_PROP_BUFFERSIZE 1`, TCP transport, drop to the newest frame), and the watcher sees a frame well under half a second after the event. The 1–2 s start-up gap is a keyframe wait, which is why the session stays open. To be measured on park-lab against the motion-push timestamp once a camera is on the bench. 2. **Trigger and window.** Nothing runs while the lane is empty. A motion push starts a *watch* on that camera; it holds while pushes keep arriving (1–3 s apart while a car moves — see [[lane-presence-and-anpr-entry]]) and ends a few seconds after they stop, or at a hard cap. 3. **Detection + tracking.** The existing YOLOX vehicle detector gives a box per car; a small in-house tracker matches boxes between frames by overlap and follows each track's **bottom-centre point** (ground contact; stable under perspective). No tracker library. 4. **The segment.** Drawn once per camera in Setup over a live frame; stored as two normalised points + which side is A, in the same normalised frame the plate/vehicle boxes already use. Crossing = sign change of the cross product of the tracked point against the segment. A→B on the entry camera is a passage; the exit camera has its own line. A→B→A inside the window is a reversal (not a passage). The verdict carries the track's plate if ANPR read one on it. 5. **One watcher, two consumers.** The same decoded frames feed the ANPR bridge (subscriber auto-open) and the crossing tracker (confirmation). 6. **Lane state becomes positive.** Busy while any track is between the line and the boom; free when the last track crossed or left the frame; the 30 s TTL stays only as a fallback when the stream is down. `vehicle_passed` ⇒ lane free *unless another track is present* (tailgating). This is the software form of the pass-through sensor [[entry-double-press]] asked for. ### Ledger semantics (append-only, unchanged open path) - `vehicle_entry` / `vehicle_exit` remain **intent**: the barrier was commanded open. The open is never delayed by confirmation. - `vehicle_passed` (new, signed): the crossing was seen, with how (vision track) and the plate. - `entry.abandoned` / `exit.abandoned` (new, signed): window ended with no crossing. Closes the occurrence; a printed ticket is **invalidated** so the paper cannot be handed to the next car. - *unverified*: vision/stream unavailable — recorded as such; the stay counts (benefit of doubt). Occupancy and the active list count passed + unverified; abandoned are listed as what they are. A subscriber's stay only exists once the car is seen to cross — which also kills the stale FIFO occurrence at its root. ### Closing the boom after an abandonment — evidence-driven, never timed [[barrier-not-a-door]] stays: no timed close. A close may be **expressed** (a pulse on a spare Dingtian channel into the operator's *close* input) only when **all** hold: an abandoned verdict; the tracker reports nothing between the line and the boom and nothing approaching, for a few seconds; no new open since; the watch is alive (stream up, verdict fresh); and the close is itself a signed event with the last frame attached. Vision down ⇒ no close, ever (today's behaviour). The operator's safety devices (loop / photocell) must be verified to override a close command on the real unit before this ships. Requires a revision (not repeal) of the standing decision, with the test results attached. ## Test plan — on park-lab (user, 2026-10-24: "we will test it on park-lab") 0. Verify the interlock with a meter: hold the open relay, pulse the close relay, `DOWN` must stay dead. Then assert `UP` and `DOWN` together on the unit: open must win. 1. Confirm the operator's close input; wire a spare relay to it. 2. Close with a car on the safety loop → boom must not move / must reverse. 3. Close with the photocell beam broken by a person → same. 4. Reversal: open, back out, window expires → close pulses, boom comes down. 5. Tailgate: second car approaching while the first backs out → the tracker holds the close. 6. Vision service stopped: reversal again → boom stays up, event logged unverified. ## Measured on park-lab (2026-10-24, i5-9500, vision container, CPU only) YOLOX-S ONNX, input fixed at 640 by the exported graph (smaller inputs need a re-export): | intra-op threads | ms / frame (p50) | ≈ fps on that budget | | --- | --- | --- | | 2 (service default) | 132 | 7.5 | | 4 | 79 | 12.5 | | 6 | 66–70 | 14 | Decode of a 704×576 sub-stream frame is < 1 ms (MPEG-4 part 2 proxy; H.264/H.265 will be a few ms) — negligible next to inference. So one lane at 5–6 fps costs ~0.7–0.8 of two cores during a watch and nothing between watches; two lanes at once need 4 threads or detection on alternate frames with the tracker interpolating. Cheaper still: re-export YOLOX at 416 (~2.4× fewer FLOPs) or switch to YOLOX-Tiny/Nano for the tracker (the plate stage keeps its own detector). ## park-lab rig (2026-11-15) Two cameras mounted on **one physical lane that serves both directions** (user, 2026-11-15): | | Entry camera | Exit camera | |---|---|---| | Address | `10.0.10.6` | `10.0.10.7` | | Model | DS-2CD1083G2-LIU (8MP, V5.8.4) | DS-2CD1043G2-LIU (4MP, V5.8.10) | | Sub-stream (102) | 1280×720 **H.264**, 12.5 fps, keyframe every 0.96 s (since 2026-11-23; MJPEG from 2026-11-17 until then) | 1280×720 **H.264**, 20 fps, keyframe every 1 s (since 2026-11-23; MJPEG from 2026-11-17 until then) | | Line crossing / intrusion (`ISAPI/Smart/LineDetection`, `FieldDetection`) | `notSupport` | `notSupport` | | Motion detection | on, target `vehicle`, grid drawn | on, target `vehicle`, grid drawn | | Alarm server (`httpHosts`) | the dev machine `10.0.10.203:3000` (user, 2026-11-19) | the dev machine `10.0.10.203:3000` (user, 2026-11-19) | Read from the cameras over ISAPI the same day; bench snapshot results are on [[lpr-camera]]. > **Addresses vs. the 2026-11-15 record (2026-11-17):** read again over ISAPI, `.6` answers as > DS-2CD1083G2-LIU (8MP, V5.8.4, main 3840×2160 12.5 fps) and `.7` as DS-2CD1043G2-LIU (4MP, > V5.8.10, main 2560×1440 20 fps) — every attribute swapped as a set against the 2026-11-15 bench > table on [[lpr-camera]], so the two units most likely traded addresses between the bench and the > park-lab mount. Directions hold (the OSD reads "Hyrje" on `.6`, "Dalje" on `.7`); the table above > shows the current state. The same day both sub-streams were switched to **MJPEG** for the booth > live view ([[camera-live-view]]), then raised to 1280×720: every frame is now a keyframe, so item 1's "≤ 1 s I-frame" > concern no longer applies to these units; the watcher would decode MJPEG (OpenCV can) at > ~1 MB/s per camera. - The 8MP model has no line crossing either, so the constraint above holds for both: the booth PC does the tracking. - ~~Both sub-stream keyframe intervals are above the ≤ 1 s this design asks for (item 1).~~ Moot since the switch to MJPEG (2026-11-17). - Both cameras push to the local dev machine, which runs on a copy of park-lab's database where both are registered (bound to Dingtian relay 1, ANPR auto-open on). They push to the dev machine, not to park-lab, so a subscriber read there raises the real boom. - [[k200l-printer]] records `10.0.10.7` as the park-lab printer's fixed address — the exit camera now answers there. To be resolved with the user. - **Shared lane — not covered by the design above**, which assumes a camera sees only its own direction. Here a car driving in passes the entry camera and then drives away through the exit camera's view, and the reverse for a car driving out. Open in "Open questions". ## Decided with the user (2026-11-17) - **Layout.** park-lab is **one lane, one barrier** for both directions (relay 1 registered as `both`, both cameras bound to it). park-2 and park-buzi have **two lanes, two barriers**. - **Every open is watched**, not only ANPR subscriber opens: a ticket printed by someone who then drives off leaves the boom up the same way. No A→B passage inside the window ⇒ close. - **Scope, phase 1: the close only.** The ledger part (`vehicle_passed`, `*.abandoned`, ticket invalidation) is phase 2. The close itself is a signed event from the start. - **Wiring.** park-lab: R1 opens, R2 closes (`DOWN`). The user believes R2 is interlocked behind R1's NC as [[zkteco-cmp200-barrier]] prescribes; this is **not yet verified**. Relays 3 and 4 are **not** interlocked. Until a pair is verified interlocked (a meter on `DOWN` with the open relay held), that barrier gets no close. - **Relay maps at the other sites (user, 2026-11-19).** **No close relay exists at either site.** A close there needs new wiring to the operator's close input first. | Site | R1 | R2 | R3 | R4 | |---|---|---|---|---| | park-2 | opens the entry barrier | opens the exit barrier | — | — | | park-buzi | opens the entry barrier | opens the exit barrier | pulses the entry ticket button when a vehicle is in the drawn zone | — | park-buzi is offline (the site does not run this software). Config validation must refuse a close relay that already has a direction or an input role. - **The line is our own Line Crossing rule (user, 2026-11-19).** The model is Hikvision's: a segment with sides A and B and a direction, where A → B, B → A or A ↔ B is what counts as a crossing. The fleet cameras have no such rule, so Setup draws it and the booth's tracker judges. ### Unexplained passage — the audit witness (user, 2026-11-19) A vehicle that crosses a barrier's line with **no signed open behind it** is recorded as an anomaly, for audit. Typical causes: the booth operator raising the boom with a remote control or the operator's own button, which bypasses our relay and leaves no trace today, or a second car through on one open (tailgating). It is the independent witness [[append-only-event-chain]] and [[reconciliation]] call for: *a physical open with no matching signed command is the fraud signal.* - **Matching rule.** One open covers one car, because the barrier closes on the passage. A crossing in the open's direction is explained when a signed `barrier_open_command` for that barrier exists since the previous crossing there. The command may come from any source: ANPR, ticket, QR, an operator button, or a setup test. Each command explains at most one crossing. - **Record.** A signed `anomaly`, reason `passage.unexplained` (a new member of the closed reason set). It carries: - the plate and its confidence, when read; - the direction from the line; - the barrier and the camera; - the evidence still; - the crossing time, and the time of the last open that was already used. It is listed in reports and in the shift's Z-report: the operator on duty is the person it audits. - **Unsigned until it is proven.** The ledger is append-only, so a false anomaly can never be removed. Until the crossings are shown reliable on park-lab, candidates go to `device_events` (kind `passage-unexplained`) and are checked against what really happened. Signing is switched on afterwards. - **An abandoned open must stop covering cars.** A turned-back open would otherwise explain the next car through. The abandoned verdict therefore marks the open used, so the next car through is an unexplained passage. - **No camera, no claim.** Periods with the stream or vision down are recorded as unwatched, so a missing anomaly is never read as "nothing happened". - **Plates of people who are not customers** are kept as evidence. The snapshot retention applies. Whether that is enough is a decision still to be made. ### Phase-1 order (user, 2026-11-19) > **Superseded (user, 2026-11-23).** The PoC as it ran on 2026-11-22 met the user's requirements > and is the reference for building this into the parking system: the zone flow, the relay rules > and the live close, as decided on 2026-11-22 below. The staged order in this section and the > "Phase-1 shape" after it are kept as history and no longer bind the work. The audit record comes first, because it actuates nothing: no relay, no interlock, no safety review. 1. **Crossing detection.** The tracker over hub frames judges each car against the drawn lines. 2. **Unexplained passages.** Unsigned candidates in `device_events` first; signed anomalies once proven. 3. **The abandoned verdict.** The close runs as a dry run ("would close now", with the evidence frame), and the verdict marks the open used. 4. **The real close pulse.** Last, behind the per-barrier switch, after step 0 of the test plan (the interlock) and the safety tests, and after [[barrier-not-a-door]] is revised. ### Phase-1 shape (proposed) - **Built (uncommitted).** Setup → camera → *Crossing line* draws the segment over the live picture. You drag across the picture to draw it, drag an end to move it, and can swap A/B and pick A → B, B → A or A ↔ B. It is stored as camera `config.crossing` (`CrossingLine` in `packages/shared`): two normalised points and a direction, with side A on the screen-left of p1→p2. The save validates it, and `null` clears it. - The watch is **per barrier**, started by the **open** (any source), not by a camera push. A barrier without a drawn line gets no watch and no close. - The direction of the open picks the confirming line; "lane clear" must hold on **every** camera bound to that barrier (park-lab: a car approaching from the other side holds the close). - The close relay is named **explicitly** per barrier in the controller config (never derived from the open relay), may have no other role, and is a separate optional driver capability. The driver serialises open/close per barrier with open always winning — which does **not** replace the hardware interlock (a second server on the same board, e.g. a dev machine, has its own lock). - **Dry run first:** the verdict and a "would close now" record with the evidence frame; the real pulse sits behind a per-barrier switch, off by default, until the bench tests pass and [[barrier-not-a-door]] is revised. - Frames come from the live-view hub ([[camera-live-view]]): one MJPEG session per camera, shared. - A drawn **line alone may not be enough**: the entry view has parked vehicles in the background, so "nothing in view" is never true there. The recordings decide whether Setup also needs a lane area. ## First recordings — AA890XX manoeuvres (2026-11-19, night) Clips were taken by a dev recorder: both 102 streams, 25 s before to 15 s after each server event, stored in `.local-parklab/recordings/`. A prototype ran YOLOX-S on every 3rd/4th frame, with a greedy IoU tracker following the bottom-centre point, against the lines drawn in Setup. | Time (UTC) | Ledger | What happened | Entry cam `.6` | Exit cam `.7` | |---|---|---|---|---| | 16:24:09 | `vehicle_entry` | drove in | A → B at 16:24:12 | no crossing | | 16:24:46 | `vehicle_exit` | drove out | B → A at 16:24:51 | no crossing | | 16:25:20 | `vehicle_entry` | **turned back** | A → B 16:25:12, B → A 16:25:19 | car never reached it | - **The turn-back is visible**, and the ledger holds a false entry for it: the subscriber now has an open stay. This is the case this page exists for. - **The entry line sits where cars stop to be read.** In the turn-back the car crossed A → B eight seconds **before** the open, then went back over the line. With "A → B after the open" as the rule, a car already over the line when the boom rises and then driving on would never cross again. It would be judged abandoned, and a close would come down on it. The line must lie **beyond the stopping point and the boom**, where a car only gets after passing. - **The exit line is off the cars' path.** It is drawn in the bottom-left corner, while cars drive along the right half of the frame. Near the frame edge the car is cut off, and the bottom-centre point jumps. - **On this one-lane rig the entry camera alone saw both directions** (A → B in, B → A out). The shared-lane open question leans toward one well-placed line per barrier, with direction from the crossing. - **The boom swings through the exit camera's view** when it opens (16:24:11–15, 16:24:48–51) and stayed in view after the turn-back (16:25:22 onwards, boom still up). That would let a camera see that the boom is up, a direct witness of an open by remote control. Not yet confirmed with the user. ## Field trials — zone PoC (2026-11-21) A standalone prototype tried this design on park-lab with the real relays: R1 live, R2 as a dry run. The entry camera judged every move of a night drive right, including nose over the line and reverse. The user set the close rule, and the exit camera was dropped because the rising boom crosses its image. The details are on [[zone-anpr-poc]]. **2026-11-22:** the flow and relay rules below were built into the prototype and run with R2 live. By day the entry visits were judged as driven, except one turn-back at the boom that was decided `passed` while the zone ended short of the picture's edge; the boom came down at every abandonment the camera judged. On a wet night the plate and the detector did not hold ([[zone-anpr-plate-trials]]). The user closed the trials there; what is left to harden is on [[vision-hardening]]. ## Decided with the user (2026-11-22) — the zone flow and the relay rules ### The flow - **A → B is in, B → A is out.** The two are mutually exclusive: a later crossing replaces the earlier one, so only the **last** crossing counts. - **No decision while the zone is busy**, neither passed nor abandoned. The watch keeps running. - **The decision is made when the zone becomes free:** | Zone | Last crossing | Decision | R2 | |---|---|---|---| | busy | any, or none | none yet | — | | free | A → B | passed | nothing | | free | B → A | abandoned | fire | | free | none: the vehicle did not cross | abandoned | fire | - **The rule behind the last two rows (user):** *"We care if the boom is up (the barrier is open) and the transient or subscriber do not cross the barrier, so we flag that entry as abandoned, and fire R2 to close the boom."* It holds for ticket holders and subscribers alike. - R2 fires only for an open made in that busy period, as before ([[zone-anpr-poc]]). - This replaces the six verdicts of the PoC ("moving away", "other direction", "stayed beyond"). The PoC implements it since 2026-11-22: [[zone-anpr-poc]], "The 2026-11-22 build". **Not settled** (raised by [[zone-anpr-poc-review]], not yet confirmed by the user). The PoC build had to pick a default for each; they are listed on [[zone-anpr-poc]]: - **What counts as busy.** The review recommends any vehicle in the zone, on every camera bound to the barrier. The PoC build looks at any vehicle in the camera's own zone. - **A vehicle the detector loses while it stands in the zone** makes the zone look free. With no crossing, that gives abandoned and a close on a standing car (finding 1 there). The review recommends that the zone counts as free only when the vehicle was seen leaving it. - **A drive-out on park-lab's shared lane is also B → A.** R2 then fires behind a car that has left. With the zone empty that harms nothing, but "abandoned" is the wrong word for it once the verdict feeds the ledger. ### Relay rules - **The close does not look at the boom (user).** No "boom is down" signal is needed for it. What matters is that the boom was opened and the vehicle did not cross. *"If the boom is already closed that R2 firing will do nothing."* Not yet tried on the unit: a `DOWN` pulse on a closed boom belongs in the bench tests above. - **A vehicle under the boom is the barrier's concern, not the host's (user, 2026-11-22).** The barrier's own radar or infrared sensors keep the boom up while something is under it, whatever the relay commands. The close therefore only has to know that the open was not used. - So the limit contacts (`O.LM OUT`, `C.LM OUT` on [[zkteco-cmp200-barrier]]) are **not** wired for the close. Their use as an audit witness is a separate matter. - **What the board reports.** The status read returns each relay's coil state and the inputs (`packages/devices/src/drivers/access-dingtian.ts`, command `0x00`). A coil is on only during its 500 ms pulse, so this never says where the boom is. The PoC reads it before every pulse. - **Read, then fire (user, 2026-11-22).** Before a relay is pulsed, the board's status is read. If the other relay of the pair is off, the pulse goes out. Switching a relay off takes no time beyond the network, and a pulse lasts 500 ms, so the other relay is almost always off. - **When the other relay reads on (user, 2026-11-22).** Send it an off command and read again. Once it reads off, fire. If it still reads on, keep trying. The rule is the same in both directions. - **When the read fails (user, 2026-11-22).** Check whether the relay controller is online. If it is, keep looping. If it is not, there is no controller on the network to drive, and the relay is flagged **offline**. - **Contradiction, noted.** Being the same in both directions, the rule lets a close switch R1 off. That is "last command wins", where [[zkteco-cmp200-barrier]] and the phase-1 shape above ask for "open wins". It can only bite when an open from another source (the app on the dev machine, an operator button) lands in the half second before a close: that open is cut and the boom comes down in front of the car it was for. The series interlock still makes open win on the wire. - **Built this way in the PoC (2026-11-22), not yet confirmed by the user:** - "online" is a TCP connect to the board's web port, a different probe from the status read; - 0.1 s between tries; one worker per board, and a newer command replaces one still trying; - a close that is still looping when the zone turns busy again is dropped, since the flow decides nothing while the zone is busy. - The read and the pulse are separate datagrams, and the dev machine drives the same board, so the check is not atomic. It does not replace the series interlock, which stays a precondition for a live R2. ## Where the video work lives (user, 2026-11-23) Decided by the user, and now part of a refactor of the whole repository: [[event-driven-refactor]] has the full list, what is not decided, and what it touches in the code. - **The server holds no video or image work.** The vision side talks to the cameras, decodes whatever they send, and produces what the rest needs. - **The server is agnostic about the camera side.** A camera's signal is one way in among several; without it an RF card, a barcode or a push-button ticket does the job. The server does nothing special when a camera is blind or dead. For this page that keeps the rule "no signal, no close". - **A bus connects the vision side, the server and the booth screen.** How the booth gets its picture and how the vision side gets the camera logins settle with the user's guidelines. - **Tried the same day:** the PoC decoding H.264 sub-streams costs the same CPU as MJPEG and an eighth of the network ([[zone-anpr-poc]], "H.264 instead of MJPEG"). - Today the server still holds the live-view stream, pulls and re-encodes the stills, and reads picture sizes ([[camera-live-view]], `apps/server/src/snapshot.ts`). Nothing has been moved. ## Open questions - **Hardening the vision side** after the field trials: the work list, deferred on 2026-11-22, is [[vision-hardening]]. - **One lane, both directions (park-lab rig).** The PoC lets one camera own the lane at a time, and the entry camera alone judges both directions ([[zone-anpr-poc]]). Every car crosses both cameras' views. Does the far camera's motion push for a car moving *away* count as nothing (direction from the track decides), and may the far camera's sighting corroborate the passage? Undecided. - Re-export YOLOX at 416 vs YOLOX-Tiny for the tracker — accuracy on far cars at the line? - ~~Window cap and "lane clear" dwell before a close (start: cap 60 s, dwell 3 s).~~ Decided by the user (2026-11-21): no window, no dwell. The close fires as soon as the zone is free and the verdict is abandoned. See [[zone-anpr-poc]]. - Does the DS-2CD1043G2-LIU keep pushing VMD for a car *reversing*? (It should — motion is motion.) - Stream-to-event latency and frame drop rate on the booth PC (measure, don't assume). - Which barrier operator model is at the sites? The unit on hand is a [[zkteco-cmp200-barrier]]: its close input is `DOWN` (dry contact to `G`), and the manual says `DET`/`PHO` reverse a falling boom — steps 1–3 can be run on it. Related: [[lane-presence-and-anpr-entry]], [[barrier-not-a-door]], [[entry-double-press]], [[append-only-event-chain]], [[opencv-anpr-service]], [[park-2-event-loop-stall]].