Accept a camera read only when three frames agree
One frame was enough to accept an ISBN, on the theory that the check digit makes a false read unlikely. About one multi-digit misread in ten still passes the check, and a single book put two phantom ISBNs in the queue. A read now has to repeat on three consecutive frames (two in a capture burst), and a frame that yields two different ISBNs is ignored. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
a210576661
commit
ddf6020731
5 files changed
+172
-22
No files matched your search
+9
-3
@@ -1,5 +1,5 @@
|
||||
import { prepareZXingModule } from 'zxing-wasm/reader';
|
||||
import { acceptRead, markEmitted, newReadState } from './readstate.ts';
|
||||
import { acceptRead, agree, markEmitted, newReadState } from './readstate.ts';
|
||||
import { cropRect } from './frame.ts';
|
||||
import { decodeLive, decodeThorough, newLiveState, sharpness, wantsFull } from './decode.ts';
|
||||
import type { DecodeOutcome, Pixels } from './decode.ts';
|
||||
@@ -81,6 +81,7 @@ export interface Scanner {
|
||||
|
||||
const FRAME_FALLBACK_MS = 60;
|
||||
const BURST_MS = 1500;
|
||||
const BURST_AGREE_READS = 2;
|
||||
|
||||
/** Ask for the biggest picture the camera has; failures are ignored (the camera keeps what it gave). */
|
||||
async function wantResolution(track: MediaStreamTrack | undefined): Promise<void> {
|
||||
@@ -181,8 +182,13 @@ export async function startScanner(
|
||||
const out = await decodeThorough(crop, full);
|
||||
other ??= out.other;
|
||||
if (out.isbn) {
|
||||
state = markEmitted(state, out.isbn, Date.now());
|
||||
return { isbn: out.isbn, other, saved: null };
|
||||
// The same agreement rule as the live loop, a little looser (two frames) since the burst is short and was asked for.
|
||||
const a = agree(state, out.isbn, Date.now(), BURST_AGREE_READS);
|
||||
state = a.state;
|
||||
if (a.agreed) {
|
||||
state = markEmitted(state, out.isbn, Date.now());
|
||||
return { isbn: out.isbn, other, saved: null };
|
||||
}
|
||||
}
|
||||
}
|
||||
if (other) return { isbn: null, other, saved: null };
|
||||
|
||||
Reference in new issue
Block a user