Camera view: wait 2.5 s of a still, readable band before the photo
On a phone the camera view took the photo too soon: a second of a
readable band, while the hand still moved. Now it takes the photo by
itself only when the band has looked readable and the picture has stood
still (mean change of a band pixel between checks under 6 of 255) for ten
checks in a row, 2.5 s, and never in the first 1.5 s. The hint counts
down ("the photo is taken in 2 s, or press Take the photo"), and says
"Hold still: the picture still moves" while it moves. Take the photo
still takes it at once.
Checked with fake cameras in Edge at 390x844: glare and dark keep their
hints and never take a photo, a feed that moves is never taken in 8 s, a
still good one is taken after 4.0 s and read with every check digit.
This commit is contained in:
1 parent
0d3b2d8b84
commit
a6ebdfc89c
2 files changed
+50
-12
No files matched your search
+5
-3
@@ -453,9 +453,11 @@ Planned on November 20, 2026, from Alex's answers (decisions table).
|
|||||||
reuse `templates/_mrz_photo.html`). "Take a photo" opens a camera view:
|
reuse `templates/_mrz_photo.html`). "Take a photo" opens a camera view:
|
||||||
a frame of the photo page's shape and a band for the two lines, with
|
a frame of the photo page's shape and a band for the two lines, with
|
||||||
a hint that says when it is too dark, when there is glare on the
|
a hint that says when it is too dark, when there is glare on the
|
||||||
lines, when no lines are in the band or the picture is not sharp, and
|
lines, when no lines are in the band, the picture is not sharp or
|
||||||
that takes the photo by itself once the band has looked readable for
|
still moves, and that takes the photo by itself once the band has
|
||||||
a second. "Choose a picture" reads any image (EXIF orientation, the
|
looked readable and stood still for 2.5 seconds (never in the first
|
||||||
|
1.5 seconds; a second was too quick on a phone, Nov 20), counting
|
||||||
|
down in the hint; "Take the photo" takes it at once. "Choose a picture" reads any image (EXIF orientation, the
|
||||||
four quarter turns, a tilt either way). Reading happens in the browser
|
four quarter turns, a tilt either way). Reading happens in the browser
|
||||||
(`static/mrz-photo.js`): Tesseract.js 7 with Doubango's MRZ model, all
|
(`static/mrz-photo.js`): Tesseract.js 7 with Doubango's MRZ model, all
|
||||||
served by the app (`static/vendor/tesseract/README.txt`, about 6 MB,
|
served by the app (`static/vendor/tesseract/README.txt`, about 6 MB,
|
||||||
|
|||||||
+45
-9
@@ -481,6 +481,16 @@
|
|||||||
// the variance of the band's Laplacian below which it is not sharp yet,
|
// the variance of the band's Laplacian below which it is not sharp yet,
|
||||||
// measured on the band scaled to 320 pixels across
|
// measured on the band scaled to 320 pixels across
|
||||||
var SHARP = 150;
|
var SHARP = 150;
|
||||||
|
// The photo takes itself only once the band has looked readable and the
|
||||||
|
// picture has stood still for HOLD checks in a row (one every 250 ms, so
|
||||||
|
// 2.5 s), and never in the first START ms, while the passport is still
|
||||||
|
// being put into the frame. A second was too quick on a phone: it took
|
||||||
|
// the photo while the hand still moved.
|
||||||
|
var HOLD = 10;
|
||||||
|
var START = 1500;
|
||||||
|
// the mean change of a band pixel from one check to the next (0 to 255)
|
||||||
|
// above which the picture still moves
|
||||||
|
var STILL = 6;
|
||||||
|
|
||||||
// What is wrong with the band in the picture, or "" when it looks
|
// What is wrong with the band in the picture, or "" when it looks
|
||||||
// readable: too dark, glare, no lines in it, or not sharp.
|
// readable: too dark, glare, no lines in it, or not sharp.
|
||||||
@@ -512,18 +522,28 @@
|
|||||||
}
|
}
|
||||||
var sharp = n ? s2 / n - (s1 / n) * (s1 / n) : 0;
|
var sharp = n ? s2 / n - (s1 / n) * (s1 / n) : 0;
|
||||||
var m = { mean: Math.round(mean), glare: bright / g.length, ink: ink / g.length, sharp: Math.round(sharp) };
|
var m = { mean: Math.round(mean), glare: bright / g.length, ink: ink / g.length, sharp: Math.round(sharp) };
|
||||||
if (mean < 50) return { why: "Too dark: find more light.", m: m };
|
if (mean < 50) return { why: "Too dark: find more light.", m: m, g: g };
|
||||||
if (m.glare > 0.02) {
|
if (m.glare > 0.02) {
|
||||||
return {
|
return {
|
||||||
why: "Glare on the two lines: tilt the passport a little, or turn away from the lamp.",
|
why: "Glare on the two lines: tilt the passport a little, or turn away from the lamp.",
|
||||||
m: m,
|
m: m,
|
||||||
|
g: g,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (m.ink < 0.04) {
|
if (m.ink < 0.04) {
|
||||||
return { why: "Put the two lines at the bottom of the photo page into the yellow band.", m: m };
|
return { why: "Put the two lines at the bottom of the photo page into the yellow band.", m: m, g: g };
|
||||||
}
|
}
|
||||||
if (sharp < SHARP) return { why: "Hold still: the lines are not sharp yet.", m: m };
|
if (sharp < SHARP) return { why: "Hold still: the lines are not sharp yet.", m: m, g: g };
|
||||||
return { why: "", m: m };
|
return { why: "", m: m, g: g };
|
||||||
|
}
|
||||||
|
|
||||||
|
// The mean change of a pixel between two looks at the band; Infinity
|
||||||
|
// when there is no earlier look of the same size.
|
||||||
|
function moved(a, b) {
|
||||||
|
if (!a || !b || a.length !== b.length) return Infinity;
|
||||||
|
var sum = 0;
|
||||||
|
for (var i = 0; i < a.length; i++) sum += Math.abs(a[i] - b[i]);
|
||||||
|
return sum / a.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function el(tag, cls, text) {
|
function el(tag, cls, text) {
|
||||||
@@ -621,6 +641,8 @@
|
|||||||
|
|
||||||
var timer = 0;
|
var timer = 0;
|
||||||
var good = 0;
|
var good = 0;
|
||||||
|
var last = null;
|
||||||
|
var opened = Date.now();
|
||||||
var done = false;
|
var done = false;
|
||||||
var small = canvas(320, 80);
|
var small = canvas(320, 80);
|
||||||
var sctx = small.getContext("2d", { willReadFrequently: true });
|
var sctx = small.getContext("2d", { willReadFrequently: true });
|
||||||
@@ -658,12 +680,26 @@
|
|||||||
small.height = Math.max(8, Math.round((bh * 320) / bw));
|
small.height = Math.max(8, Math.round((bh * 320) / bw));
|
||||||
sctx.drawImage(video, bx, by, bw, bh, 0, 0, 320, small.height);
|
sctx.drawImage(video, bx, by, bw, bh, 0, 0, 320, small.height);
|
||||||
var j = judge(sctx, 320, small.height);
|
var j = judge(sctx, 320, small.height);
|
||||||
hint.textContent = j.why || "Good. Hold still...";
|
var change = moved(last, j.g);
|
||||||
root.classList.toggle("good", !j.why);
|
last = j.g;
|
||||||
|
j.m.moved = Math.round(change * 10) / 10;
|
||||||
|
// the first look has nothing to compare with: not still yet, but
|
||||||
|
// nothing to say about it either
|
||||||
|
var why = j.why || (change > STILL && change !== Infinity ? "Hold still: the picture still moves." : "");
|
||||||
|
var early = Date.now() - opened < START;
|
||||||
|
good = why || early || change > STILL ? 0 : good + 1;
|
||||||
|
if (why) {
|
||||||
|
hint.textContent = why;
|
||||||
|
} else if (early) {
|
||||||
|
hint.textContent = "Good. Hold still...";
|
||||||
|
} else {
|
||||||
|
var left = Math.max(1, Math.ceil(((HOLD - good) * 250) / 1000));
|
||||||
|
hint.textContent = "Good. Hold still: the photo is taken in " + left + " s, or press Take the photo.";
|
||||||
|
}
|
||||||
|
root.classList.toggle("good", !why);
|
||||||
root.setAttribute("data-measure", JSON.stringify(j.m));
|
root.setAttribute("data-measure", JSON.stringify(j.m));
|
||||||
good = j.why ? 0 : good + 1;
|
// a readable band that stands still for HOLD checks takes the photo
|
||||||
// a steady, readable band for about a second takes the photo
|
if (good >= HOLD) {
|
||||||
if (good >= 4) {
|
|
||||||
take();
|
take();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user