Passport photo reader: a camera view with a frame, read in the browser
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Successful in 28s

On the new person and new passport forms, next to Read:

- "Take a photo" opens a camera view (getUserMedia, the back camera): a
  frame of the photo page's shape (125 by 88 mm), a band for the two lines,
  and a hint from four checks of the band four times a second: too dark,
  glare on the lines, no lines in the band, not sharp yet (variance of the
  Laplacian). Once the band has looked readable for a second it takes the
  photo itself; "Take the photo" and Cancel (or Escape) are there too.
  The band where the frame showed it is read first; when that holds no
  zone, the whole frame is searched.
- "Choose a picture" reads any image: EXIF orientation, the four quarter
  turns, a tilt of 7 degrees either way; a failed read says when there is
  glare in the picture.

Reading happens in the browser (static/mrz-photo.js): even light from a
local mean, the lines found with Tesseract's page layout, then the band cut
along their baselines, scaled and read as one block. Tesseract.js 7.0.0
and its core (SIMD and plain LSTM builds) with Doubango's MRZ model, all
served by the app from static/vendor/tesseract/ (README.txt: sources, npm
integrity, SHA-256, licenses Apache-2.0 and BSD-3), loaded at the first
photo. The photo never leaves the device: only the lines go into the zone's
field, and Read is pressed.

The server reads them like typed ones, through mrz::from_ocr when they are
no clean zone: the first line wherever it is, the second whose check digits
match best, a miscounted filler run cut or filled, K for < in the filler,
letters and digits where the zone has them, and look-alikes (O for 0, B for
8) swapped in the number fields only where a check digit asks for it,
preferring a digit. A photo's note asks to compare the names, which have no
check digit.

Only those two pages and the reader's files allow WebAssembly
('wasm-unsafe-eval', worker-src 'self', img-src blob:) and the camera
(Permissions-Policy camera=(self)); every other page keeps camera=().
Content types for .wasm and .gz.

Checks: fmt, clippy -D warnings, 99 unit and 50 integration tests (new:
from_ocr cases from real reads, tests/mrz_photo.rs for the markup, the two
policies, the files and a read from photo lines). In Edge (Playwright): 12
made-up phone photos and 16 specimen pages from Wikimedia Commons, every
zone that is readable read with all check digits matching (not: a hard
shadow across the lines; the specimens whose zone is blanked out), 1 to 5 s
each; the camera view with a fake camera: the glare and dark hints, and a
good picture taken by itself and the form filled in. Layout check 0
problems on both forms and a person, light and dark, desk and phone.

PLAN: task 7.3 done ahead of the client link, the decision recorded.
This commit is contained in:
grabowski committed 2026-11-20 16:47:40 +07:00
1 parent fc8c1b6a44
commit 1f54d93643
24 files changed
+2130 -52

No files matched your search

+6
View File
@@ -25,6 +25,12 @@ Data Protection Act (PDPA) asks.
windows online and in person, the window for the next extension of stay,
a decision to collect, overstay, TM.30 after each arrival, the passport's
and the work permit's expiry, and visas still to be used.
- The passport's zone from a photo: on the new person and new passport
forms, "Take a photo" opens a camera view with a frame for the photo page
and a band for the two lines, says when there is glare or too little
light, and takes the photo once the lines look readable; "Choose a
picture" reads any image. The reading happens in the browser, so the
photo stays on the device, and the check digits catch a misread.
- A list of people with a filter and each person's next deadline, and a
page per person with six tabs: the overview with personal details,
passports and addresses; "Visa and stay" with arrivals and departures,