feat(review): sample every detected car, not only ticketed entries
Build & push images / images (push) Successful in 5m20s
Build & push images / images (push) Successful in 5m20s
The entry stream for the reviewer was fed from the session-tied read only (ticket printed / exit signed). park-2 ran an afternoon with its barriers up: hundreds of camera vehicle pushes, zero tickets, zero samples. - anpr-entry: keep the best-framed vehicle of each poll loop (highest body-type confidence with a box), store that frame as a snapshot (identity pass:<id>, no session) and emit a vehicle read with the camera id — plate or no plate. One sample per detection, fire-and-forget, never on the ANPR path. - snapshot.ts: normalizedBoxes() shared by the session-tied read and the bridge; vehicle reads now carry deviceId. - review-outbox: sampleEntry(deviceId) dedups per camera for 30 s so the pass sample and a ticket entry's read (same car, seconds apart) go once. - wiki: outbox page (entry stream, troubleshooting checklist for 'nothing arrives': the month-long silence was a missing Netbird policy, not code), park-2 camera port-forward procedure (site-device-installation §7), log.
This commit is contained in:
+25
-12
@@ -2,12 +2,12 @@ import { randomUUID } from "node:crypto";
|
||||
import sharp from "sharp";
|
||||
import { and, eq, gte, sessions, deviceEvents as deviceEventsTable, snapshots, type Db } from "@parking/db";
|
||||
import { registry, type CameraDevice, type Snapshot } from "@parking/devices";
|
||||
import { reasonPayload } from "@parking/shared";
|
||||
import { reasonPayload, type NormBox } from "@parking/shared";
|
||||
import type { FastifyBaseLogger } from "fastify";
|
||||
import { devicesByDirection, type FlowDirection } from "./device-resolve.js";
|
||||
import { deviceEvents } from "./device-events.js";
|
||||
import type { EventLog } from "./event-log.js";
|
||||
import type { VisionClient } from "./vision-client.js";
|
||||
import type { VisionClient, VisionResult } from "./vision-client.js";
|
||||
|
||||
// Camera snapshot capture, fired AFTER the barrier opens and never awaited on the
|
||||
// open path (decision 2026-06-16): a snapshot is EVIDENCE, not a gate. A camera
|
||||
@@ -171,23 +171,16 @@ async function recognizePlate(
|
||||
// Boxes are kept as FRACTIONS of the analysed frame (the stored snapshot is a
|
||||
// downscaled copy — see reencodeForStorage), so the wash's review crop can cut the
|
||||
// vehicle out of whatever copy survives and blur the plate inside it.
|
||||
const frame = await frameSize(shot.bytes);
|
||||
const norm = (b: { x1: number; y1: number; x2: number; y2: number } | null | undefined) =>
|
||||
b && frame
|
||||
? {
|
||||
x1: clamp01(b.x1 / frame.w), y1: clamp01(b.y1 / frame.h),
|
||||
x2: clamp01(b.x2 / frame.w), y2: clamp01(b.y2 / frame.h),
|
||||
}
|
||||
: null;
|
||||
const boxes = await normalizedBoxes(shot.bytes, result);
|
||||
// The vehicle's body type (advisory; the wash desk's category suggestion — see
|
||||
// venue-modules.md §Vehicle category). Rides the plate's read row when there is one,
|
||||
// else a row of its own: a car with an unreadable plate is still a car of some class.
|
||||
const vehicleBox = norm(result.vehicle?.bbox);
|
||||
const vehicleBox = boxes.vehicleBox;
|
||||
const vehicle = result.vehicle
|
||||
? { bodyType: result.vehicle.bodyType, bodyConfidence: result.vehicle.confidence, ...(vehicleBox ? { vehicleBox } : {}) }
|
||||
: {};
|
||||
const plate = !result.plate || result.lowConfidence ? "" : result.plate.text.trim().toUpperCase();
|
||||
const plateBox = plate ? norm(result.plate?.bbox) : null;
|
||||
const plateBox = plate ? boxes.plateBox : null;
|
||||
if (!plate && !result.vehicle) return; // nothing trustworthy to record
|
||||
db.insert(deviceEventsTable)
|
||||
.values({
|
||||
@@ -216,6 +209,7 @@ async function recognizePlate(
|
||||
deviceEvents.emitVehicleRead({
|
||||
identity,
|
||||
direction,
|
||||
deviceId,
|
||||
read: { bodyType: result.vehicle.bodyType, confidence: result.vehicle.confidence, snapshotId, box: vehicleBox, plateBox },
|
||||
});
|
||||
}
|
||||
@@ -241,6 +235,25 @@ function clamp01(v: number): number {
|
||||
return Math.max(0, Math.min(1, v));
|
||||
}
|
||||
|
||||
/** The vehicle's and the plate's boxes as FRACTIONS of the analysed frame (null when the
|
||||
* stage found none or the frame size is unreadable). Fractions, so the box fits the
|
||||
* downscaled stored copy the wash's review crop is cut from. Shared by the session-tied
|
||||
* recognition above and the ANPR bridge's per-car pass sample (anpr-entry.ts). */
|
||||
export async function normalizedBoxes(
|
||||
bytes: Buffer,
|
||||
result: VisionResult,
|
||||
): Promise<{ vehicleBox: NormBox | null; plateBox: NormBox | null }> {
|
||||
const frame = await frameSize(bytes);
|
||||
const norm = (b: { x1: number; y1: number; x2: number; y2: number } | null | undefined): NormBox | null =>
|
||||
b && frame
|
||||
? {
|
||||
x1: clamp01(b.x1 / frame.w), y1: clamp01(b.y1 / frame.h),
|
||||
x2: clamp01(b.x2 / frame.w), y2: clamp01(b.y2 / frame.h),
|
||||
}
|
||||
: null;
|
||||
return { vehicleBox: norm(result.vehicle?.bbox), plateBox: norm(result.plate?.bbox) };
|
||||
}
|
||||
|
||||
/** Pixel size of the analysed frame (JPEG header only — cheap). Null when unreadable. */
|
||||
async function frameSize(bytes: Buffer): Promise<{ w: number; h: number } | null> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user