feat(carwash): review outbox, booth side — plate-blurred vehicle crop + the operator's choice, queued for a trusted remote reviewer
The operator's category choice is a hypothesis, not truth (user, 2026-09-06): each wash order with a vehicle read queues a package for a trusted reviewer over the private overlay (Netbird); the verdict becomes the phase-B training label and the per-operator error rate. wiki/concepts/vision-review-outbox.md. - Boxes: the vision service returns the vehicle bbox; snapshot.ts stores the vehicle and plate boxes on the read as FRACTIONS of the analysed frame (the stored snapshot is a downscaled copy); vehicleForIdentity() returns them. - carwash_review_outbox (migration 0031) + review-outbox.ts: crop = detector box + 8 % margin, ≤ 640 px, plate blurred in place from the plate box; payload carries a pseudonymous booth id and a keyed operator hash — no site name, no plate, no OSD, no bystanders; multipart POST with a per-booth bearer; 2xx → sent (image dropped); 400/404/413/415/422 → abandoned; anything else → backoff 1 min·2^n capped 6 h; voided orders and items older than 14 days abandoned unsent. Nothing queued while unconfigured. - Enqueue is fire-and-forget off the intake path in createOrder; the loop runs every CARWASH_REVIEW_INTERVAL_SEC (60) and stops on close. - GET /api/carwash/review/status (site:read) + a "Remote review" line in Setup → Car wash. - Env CARWASH_REVIEW_URL / _TOKEN / _BOOTH_ID (all three or off) documented in .env.example and forwarded by compose. - Tests: review-outbox.test.ts (crop + blur on a synthetic frame, config/pseudonyms, queue/drain/backoff/abandon, through the app). Wiki: new concept page, index, venue-modules As built, log. The collector is not built. Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
This commit is contained in:
@@ -168,13 +168,26 @@ async function recognizePlate(
|
||||
try {
|
||||
const result = await vision.analyze(shot.bytes, shot.contentType);
|
||||
if (!result) return;
|
||||
// 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;
|
||||
// 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 vehicle = result.vehicle
|
||||
? { bodyType: result.vehicle.bodyType, bodyConfidence: result.vehicle.confidence }
|
||||
? { 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;
|
||||
if (!plate && !result.vehicle) return; // nothing trustworthy to record
|
||||
db.insert(deviceEventsTable)
|
||||
.values({
|
||||
@@ -187,7 +200,7 @@ async function recognizePlate(
|
||||
identity,
|
||||
direction,
|
||||
...(plate
|
||||
? { plate, confidence: result.plate!.confidence, region: result.plate!.region ?? null }
|
||||
? { plate, confidence: result.plate!.confidence, region: result.plate!.region ?? null, ...(plateBox ? { plateBox } : {}) }
|
||||
: {}),
|
||||
...vehicle,
|
||||
modelVersion: result.modelVersion,
|
||||
@@ -215,6 +228,20 @@ async function recognizePlate(
|
||||
}
|
||||
}
|
||||
|
||||
function clamp01(v: number): number {
|
||||
return Math.max(0, Math.min(1, v));
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const m = await sharp(bytes, { failOn: "none" }).metadata();
|
||||
return m.width && m.height ? { w: m.width, h: m.height } : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** How far back a recognized entry plate is compared against other OPEN sessions'
|
||||
* entry plates. Short on purpose: the duplicate-ticket scenario is the same car
|
||||
* re-pressing within minutes; a long window would flag legit re-visits. */
|
||||
|
||||
Reference in New Issue
Block a user