Presets
Playback
Scanner pose
Printed card
Camera and light
Camera
Layers
Quality
Model check
The science
What a phone does when it reads a QR code. The camera forms an image through a (nearly) pinhole lens; the app locates the symbol, samples one brightness value per module, decides black or white, and then lets an error-correcting code repair whatever the camera, the print and the dirt damaged. This page runs the last three stages for real on frames rendered from the 3D desk scene.
Equations used by the page
- Pinhole projection: a module of width
sat distancedcoversp = f_px s / dpixels, withf_px = (H/2) / tan(FOV/2)(here FOV 80 deg, 320 px tall). Reading needs roughlyp >= 2pixels per module (Nyquist); foreshortening multiplies the short side bycos(angle)between the card normal and the viewing ray. - Thin-lens defocus: blur circle on the sensor
c = A f |d - d_f| / (d (d_f - f)),f = 5.6 mm,A = f / 1.8; it is applied as a box blur of that width in pixels. Autofocus setsd_f = dbut not closer than 7 cm. - Sensor: auto-exposure scales the 98th percentile to 0.9; shot noise has relative size
sigma = sigma0 / sqrt(L)where L is the raw white level, so a dim room is noisier. Black/white decision: Otsu threshold,argmax w_B w_F (mu_B - mu_F)^2, over the module samples. - Reed-Solomon over GF(256), primitive polynomial
x^8+x^4+x^3+x^2+1(0x11D): codewordc(x) = d(x) x^n + (d(x) x^n mod g(x)),g(x) = prod_{i=0}^{n-1} (x - a^i). Decoding: syndromesS_j = r(a^j), Berlekamp-Massey for the error-locator, Chien search for the positions, magnitudes from a linear system, then all syndromes are re-checked. A code withncheck codewords corrects up tot = floor(n/2)wrong codewords. - Level L/M/Q/H check codewords: version 1 has 7/10/13/17, version 2 has 10/16/22/28. If a fraction
pof codewords is corrupted at random the decode probability isP(Binomial(N, p) <= t)(graph 1).
Honest simplifications
Real scanners find the three finder patterns blindly and estimate the version and the perspective from them; here the page projects the known module centres through the exact camera (the pose is known), so the finder search is skipped. Only versions 1 and 2, byte mode and a single Reed-Solomon block are implemented. Damage is painted as random blobs, which is not how scratches or creases look; the camera has no lens distortion, rolling shutter or demosaicing. Graph 1 uses the idealised random-codeword model, while real damage is spatially clustered, so the dots (an actual decoder run) and the curve agree only for random errors.
Checks run in the page
(1) The generator polynomial of the 7-check code and the 15-bit format words against the ISO 18004 values. (2) Encode, build the matrix, read it back and decode 96 random strings across all four levels; then exactly t and t+1 random codeword errors. (3) Pixels per module from projected module centres against the closed form f_px s / d.