Skip to content
The record
Finding11 July 20264 min read

Scanning in a warehouse: native barcode detection, full-resolution OCR, and three rounds of correction

Choosing the browser's native BarcodeDetector and full-resolution still-photo OCR over a per-device commercial SDK licence, and what three rounds of correction taught — extract a vendor's service tag rather than the most confident string, do not crop away the pixels OCR needs, and show the operator which engine is actually running.

methoditad-lifecyclehardware-testing

What was done

Identification by camera was built instead of licensing a commercial scanning SDK per device: the browser's native BarcodeDetector where it exists, ZXing in the page where it does not, and a full-resolution still photograph run through OCR for labels that carry no barcode. Three rounds of correction followed the first warehouse use. Picking the most confident string was wrong — a Dell label also carries the express service code, FCC identifiers and regulatory model numbers — so selection became a ladder that anchors on the printed caption, falls back to the express service code, then to tag-shaped tokens with regulatory prefixes excluded. An aiming box that cropped detection was added and then removed, because cropping discards the pixels OCR needs and a live video frame is lower resolution than a still. The torch toggle was made resilient and the engine actually running was put on screen, and one normaliser was applied to both barcode and OCR output so the same device could not enter the system under two spellings.

 live video                     still photograph
     |                               |
     v                               v
 BarcodeDetector (native)        OCR at full res
     |  absent or unsupported        |
     v                               v
 ZXing, in the page              pickSerial ladder
     |                             caption, then
     v                             express code,
 pickBarcode: 7-char tag          then tag shape
 over express service code         minus regulatory
     +---------------+---------------+
                     v
       one normaliser, then the asset tag

Two paths into the same tag: barcode off live video, text off a still photograph.


Status

Shipped, 11 July 2026.

The problem

Every device has to be identified by its serial or service tag. Typing them is slow and error-prone; the labels are small, often worn, and sometimes have no barcode at all — just printed text.

The decision: free, not paid

A commercial scanning SDK was considered and rejected. The system uses the browser's native BarcodeDetector for barcodes and full-resolution camera OCR for text-only labels.

The reasoning: a paid SDK is a per-device licence on hardware the business keeps buying, for a job the platform can do. The trade-off accepted is that BarcodeDetector support varies by browser, and OCR accuracy on a worn label is worse than a dedicated engine's.

What the corrections taught

The first version worked in an office and poorly in a warehouse. Three rounds:

extract the Service Tag from vendor labels, not regulatory noise. A Dell label carries the service tag, the express service code, FCC identifiers, regulatory model numbers and certification marks. Naive OCR returned whichever string it read most confidently, which was frequently a regulatory number. The fix was to know what a vendor's tag actually looks like rather than take the clearest text.

** then — the scan box, added and then removed.** A tighter box that cropped detection was added to help the operator aim. It was then dropped in favour of full-frame detection and full-resolution still-photo OCR: cropping threw away the pixels OCR needed, and a live video frame is lower resolution than a still. Taking a photograph and reading that beat streaming.

resilient torch and on-screen engine status. The torch toggle failed on some devices and the operator could not tell which detection engine was running. Showing what the software is actually doing beats letting the operator guess why it is not working.

tag normalisation. The same device scanned from a barcode and read by OCR produced different strings. One normaliser, applied to both.

Why it matters

This is the point where a device enters the system. A misread tag creates a duplicate asset or attaches a wipe record to the wrong machine.

What was deliberately not built

No server-side OCR. The image never leaves the device, which keeps a photograph of a customer's asset label off the network.

Open questions

A dedicated USB barcode gun (Honeywell) was specified later and parked — see the scanner integration plan. The camera path is what is in use.


The code

Choosing which string on the label is the serial: the caption wins, then the express service code, then shape with regulatory prefixes excluded.

function pickSerial(text: string): string {
  const up = text.toUpperCase().replace(/\|/g, 'I');
  // 1. a printed caption wins outright
  for (const re of CAPTIONED) {   // SERVICE TAG / S\/N / SERIAL NO
    const m = up.match(re);
    if (m) return m[1];
  }
  // 2. then the express service code
  const esc = up.match(/EXPRESS\s*SERVICE\s*CODE\s*[:#.\-]*\s*([0-9]{8,14})/);
  if (esc) return esc[1];
  // 3. then tag-shaped text that is not a regulatory prefix
  const tokens = up.match(/[A-Z0-9]{5,}/g) ?? [];
  const REG = /^(MSIP|CMM|IEC|ISO|NMB|ICES|CAN|DPN|DPC)/;  // abridged
  return tokens.find((t) => t.length === 7 && /[A-Z]/.test(t)
    && /[0-9]/.test(t) && !REG.test(t)) ?? '';
}
From apps/web/app/scan/camera-scanner.tsx — an excerpt, trimmed to the technique it illustrates.

Not shown. The regulatory-prefix list is abridged and the four caption regexes are referenced rather than spelled out. No device identifiers, customer asset tags or sample label text, and no camera-permission or upload path.

A published copy. Commit references and internal identifiers have been removed and the operator is not named; the engineering, the counts and the stated limits are unchanged.