diff --git a/src/main.js b/src/main.js index a1c16d5..315bbec 100644 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,7 @@ import { startCamera, grabFrame, imageDataFromFile } from './camera.js'; import { decodeBarcodes } from './barcode.js'; import { runOcr, isOcrAvailable } from './ocr.js'; import { recognize } from './pipeline.js'; +import { normalizeToken } from './spec.js'; import { createSession, proposeAssignment, commitAssignment, undoLast, moveEntry, removeEntry, nextStackId, @@ -88,9 +89,21 @@ async function processCapture(getFrame) { try { const frame = await getFrame(); - const { spec, source, confidence } = await recognize(frame, { decodeBarcodes, runOcr }); + // Ist einer der gleich gelesenen Codes bereits einem Stapel dieser + // Sitzung bekannt, kann die Pipeline die bis zu 20 Sekunden dauernde + // Texterkennung ueberspringen (siehe recognize() in pipeline.js). + const isKnownCode = (code) => { + const normalized = normalizeToken(code); + return targetSession.stacks.some( + (stack) => Array.isArray(stack.codes) && stack.codes.includes(normalized), + ); + }; + const { spec, source, confidence, codes } = await recognize( + frame, + { decodeBarcodes, runOcr, isKnownCode }, + ); - const plan = proposeAssignment(targetSession, spec); + const plan = proposeAssignment(targetSession, spec, codes); let stackId = plan.stackId; if (confidence === 'red' || plan.kind === 'ambiguous') { @@ -118,7 +131,7 @@ async function processCapture(getFrame) { // Sitzung bucht das Ergebnis nicht mehr nach. if (targetSession !== session) return; - const entry = commitAssignment(targetSession, spec, source, stackId); + const entry = commitAssignment(targetSession, spec, source, stackId, codes); view.setLast(describeEntry(spec, entry.stackId)); syncView();