@idmission/websdk-core 0.2.0-rc.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/client/IdmissionClient.d.ts +2 -0
- package/dist/client/IdmissionClient.d.ts.map +1 -1
- package/dist/client/IdmissionClient.js +3 -0
- package/dist/client/artifacts.d.ts +2 -0
- package/dist/client/artifacts.d.ts.map +1 -1
- package/dist/client/payload.d.ts.map +1 -1
- package/dist/client/payload.js +2 -1
- package/dist/client/types.d.ts +2 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/documentCapture/autoCaptureEngine.d.ts +106 -0
- package/dist/documentCapture/autoCaptureEngine.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureEngine.js +456 -0
- package/dist/documentCapture/autoCaptureGeometry.d.ts +424 -0
- package/dist/documentCapture/autoCaptureGeometry.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureGeometry.js +394 -0
- package/dist/documentCapture/autoCaptureGuidance.d.ts +61 -0
- package/dist/documentCapture/autoCaptureGuidance.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureGuidance.js +73 -0
- package/dist/documentCapture/autoCaptureMetadata.d.ts +185 -0
- package/dist/documentCapture/autoCaptureMetadata.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureMetadata.js +197 -0
- package/dist/documentCapture/autoCaptureOptions.d.ts +212 -0
- package/dist/documentCapture/autoCaptureOptions.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureOptions.js +178 -0
- package/dist/documentCapture/autoCaptureShutter.d.ts +162 -0
- package/dist/documentCapture/autoCaptureShutter.d.ts.map +1 -0
- package/dist/documentCapture/autoCaptureShutter.js +183 -0
- package/dist/documentCapture/controller.d.ts +33 -1
- package/dist/documentCapture/controller.d.ts.map +1 -1
- package/dist/documentCapture/controller.js +604 -40
- package/dist/documentCapture/index.d.ts +8 -2
- package/dist/documentCapture/index.d.ts.map +1 -1
- package/dist/documentCapture/index.js +6 -0
- package/dist/documentCapture/reducer.d.ts +26 -1
- package/dist/documentCapture/reducer.d.ts.map +1 -1
- package/dist/documentCapture/reducer.js +43 -0
- package/dist/documentCapture/state.d.ts +118 -0
- package/dist/documentCapture/state.d.ts.map +1 -1
- package/dist/documentCapture/state.js +24 -0
- package/dist/idCapture/controller.d.ts +20 -0
- package/dist/idCapture/controller.d.ts.map +1 -1
- package/dist/idCapture/controller.js +42 -3
- package/dist/idCapture/index.d.ts +1 -1
- package/dist/idCapture/index.d.ts.map +1 -1
- package/dist/idCapture/index.js +12 -1
- package/dist/idCapture/pipeline.d.ts +30 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -1
- package/dist/idCapture/pipeline.js +33 -10
- package/dist/models/DocumentDetection.d.ts +29 -1
- package/dist/models/DocumentDetection.d.ts.map +1 -1
- package/dist/models/DocumentDetection.js +37 -5
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.js +15 -0
- package/dist/models/defaults/index.d.ts +4 -1
- package/dist/models/defaults/index.d.ts.map +1 -1
- package/dist/models/defaults/index.js +4 -0
- package/dist/models/preloadModels.d.ts +21 -14
- package/dist/models/preloadModels.d.ts.map +1 -1
- package/dist/models/preloadModels.js +10 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -1
- package/dist/models/providers/litert/docDetectPrePost.js +5 -0
- package/dist/selfieCapture/guidance.d.ts +49 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -1
- package/dist/selfieCapture/guidance.js +51 -0
- package/dist/selfieCapture/index.d.ts +1 -1
- package/dist/selfieCapture/index.d.ts.map +1 -1
- package/dist/selfieCapture/index.js +1 -1
- package/dist/signatureCapture/controller.d.ts.map +1 -1
- package/dist/signatureCapture/controller.js +71 -21
- package/dist/signatureCapture/pipeline.d.ts +14 -2
- package/dist/signatureCapture/pipeline.d.ts.map +1 -1
- package/dist/signatureCapture/pipeline.js +30 -7
- package/dist/signatureCapture/state.d.ts +15 -0
- package/dist/signatureCapture/state.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/videoIdCapture/controller.d.ts.map +1 -1
- package/dist/videoIdCapture/controller.js +64 -3
- package/package.json +1 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two-sided window on `fill`, seeded by #343 and fixed by #380 on real
|
|
3
|
+
* frames.
|
|
4
|
+
*
|
|
5
|
+
* `FILL_MAX` is the anti-crop gate: a capture zoomed into the address block has
|
|
6
|
+
* paper edge to edge, so its fill runs to ~1.0 while a complete sheet on
|
|
7
|
+
* #343's ground truth reads 0.720-0.974. `FILL_MAX` also has to absorb the skew
|
|
8
|
+
* budget (~0.03-0.05 at 10°), which #343 chose to spend here rather than gate
|
|
9
|
+
* or de-skew.
|
|
10
|
+
*
|
|
11
|
+
* `FILL_MIN` is the only thing between an applicant and a sharp unreadable
|
|
12
|
+
* capture — #344 found focus stays flat at 0.86-0.93 on a sheet shrunk to 0.4
|
|
13
|
+
* linear, because the crop IS the box, so focus can never catch "too far".
|
|
14
|
+
*
|
|
15
|
+
* **Fixed by #380** on 4 real handheld recordings (1079x1920 iPhone, printed
|
|
16
|
+
* Carta invoice, 17.5 fps, ~1000 frames), measured on frames that also pass
|
|
17
|
+
* stability — the only population the gate ever acts on:
|
|
18
|
+
*
|
|
19
|
+
* FILL_MAX 0.99 complete sheets reach p95 0.987 / max 0.996, a held capture
|
|
20
|
+
* cropped to the address block reads min 0.994 with 64 of 77
|
|
21
|
+
* frames pinned at exactly 1.0000. At 0.99, 0% of the crop
|
|
22
|
+
* passes and 3.7% of complete frames are rejected. #343's seed
|
|
23
|
+
* survived contact with a phone.
|
|
24
|
+
* FILL_MIN 0.70 the seed of 0.55 accepted **100%** of the too-far frames.
|
|
25
|
+
* A sheet held at a distance where its address is unreadable
|
|
26
|
+
* reads 0.574-0.593; readable framings bottom out at 0.710.
|
|
27
|
+
* At 0.70: 0% of readable rejected, 7.9% of too-far accepted
|
|
28
|
+
* (all of them transition frames, none from the held segment).
|
|
29
|
+
*
|
|
30
|
+
* Both distributions OVERLAP — complete max 0.996 against crop min 0.994,
|
|
31
|
+
* readable min 0.710 against too-far max 0.721. These are operating points in
|
|
32
|
+
* a ~0.01-wide gap, not separators, and that is the honest description of what
|
|
33
|
+
* this quantity can do. #380's simulation is what makes them defensible: over
|
|
34
|
+
* all four recordings the gate fires within a second on a good frame and never
|
|
35
|
+
* fires while the sheet is cropped.
|
|
36
|
+
*
|
|
37
|
+
* Measured on ONE phone, ONE sheet, Carta only (no A4 was available) — and the
|
|
38
|
+
* skew budget #343 estimated at 0.03-0.05 is still UNMEASURED, which matters
|
|
39
|
+
* because FILL_MAX has only 3.7% margin and tilt eats exactly that.
|
|
40
|
+
*/
|
|
41
|
+
export const POA_FILL_MAX = 0.99;
|
|
42
|
+
export const POA_FILL_MIN = 0.7;
|
|
43
|
+
/**
|
|
44
|
+
* Focus floor, seeded by #344 in a POA-SPECIFIC slot rather than reusing
|
|
45
|
+
* `defaultFocusThresholds.singlePage` — that slot is keyed by
|
|
46
|
+
* `detectedDocumentType` and #361 established class 22 still owns paper IDs,
|
|
47
|
+
* and its 0.3 mobile value was a verbatim copy of the idCard entry (`55e1d527`,
|
|
48
|
+
* 2024-12-12) that was never tuned: it passes 5 of 11 visibly-blurred frames.
|
|
49
|
+
* 11 real POA captures score 0.871-0.921, so 0.6 left 1.45x headroom.
|
|
50
|
+
*
|
|
51
|
+
* **#380 took the fallback.** #344's corpus is stills an applicant chose to
|
|
52
|
+
* send; live handheld frames sit lower. On the 272 frames of #380's recordings
|
|
53
|
+
* that would have captured but for focus, 0.6 rejects 4.8% and 0.5 rejects
|
|
54
|
+
* 1.8%, with p05 at 0.670 — 0.6 is biting into the live tail. The distribution
|
|
55
|
+
* is bimodal (motion-blurred frames land at 0.29-0.50), so 0.5 still catches
|
|
56
|
+
* everything genuinely blurred.
|
|
57
|
+
*/
|
|
58
|
+
export const POA_FOCUS_THRESHOLDS = { desktop: 0, mobile: 0.5 };
|
|
59
|
+
/**
|
|
60
|
+
* Confidence floor before a box is trusted for geometry at all. Mirrors
|
|
61
|
+
* `passportBooklet.ts`'s MIN_BOOKLET_SCORE: the detector emits low-score false
|
|
62
|
+
* positives that would otherwise corrupt every margin below.
|
|
63
|
+
*
|
|
64
|
+
* **Raised from 0.3 to 0.55 by #380, and this is the single most consequential
|
|
65
|
+
* constant on this page.** At 0.3 a box scoring 0.31 is trusted exactly as much
|
|
66
|
+
* as one scoring 0.85 — and the low-scoring boxes are the SPILLED ones, which
|
|
67
|
+
* #343 established are geometrically indistinguishable from a correct box
|
|
68
|
+
* (both are large, both have small margins) and cannot be told apart by any
|
|
69
|
+
* fill threshold. #380 watched that leak: on a recording of a sheet held too
|
|
70
|
+
* far away to read, the fill window alone still let 6 frames through to
|
|
71
|
+
* capture, every one of them on a POA box scoring under 0.50.
|
|
72
|
+
*
|
|
73
|
+
* 0.55 closes that leak completely at zero cost — across #380's four
|
|
74
|
+
* recordings the two well-framed ones still fire at 0.0s and 0.8s, unchanged.
|
|
75
|
+
* The margin is thin (readable holds have a p05 of 0.563), so this is an
|
|
76
|
+
* operating point on one device; the DIRECTION — that 0.3 is far too low to
|
|
77
|
+
* gate a capture on — is the durable part.
|
|
78
|
+
*/
|
|
79
|
+
export const POA_MIN_SCORE = 0.55;
|
|
80
|
+
/**
|
|
81
|
+
* Labels the framing geometry may be measured on, in priority order.
|
|
82
|
+
*
|
|
83
|
+
* `POA` (LiteRT class 23) is the specialized class, but #342 established that
|
|
84
|
+
* the class is only a "there is paper here" trigger — it holds ~0.81-0.83 on a
|
|
85
|
+
* sheet cropped to a quarter of its area — so the anti-crop guarantee rests
|
|
86
|
+
* entirely on the geometry below. The fallbacks let the same instrument run
|
|
87
|
+
* against the SHIPPING detector, which has no POA class, so the overlay is
|
|
88
|
+
* useful before #354 lands the official export.
|
|
89
|
+
*
|
|
90
|
+
* `Document back` is in the list because real POA sheets read as one. On a
|
|
91
|
+
* printed utility bill the detector routinely scores it ABOVE the POA class
|
|
92
|
+
* (0.73 vs 0.59 on the sheet that prompted this), which is unsurprising: a
|
|
93
|
+
* dense page of text and a card back look alike to a detector trained mostly
|
|
94
|
+
* on IDs. Without it, a frame where POA dipped under `POA_MIN_SCORE` fell all
|
|
95
|
+
* the way through to "no document detected" while the model was confidently
|
|
96
|
+
* looking straight at the page.
|
|
97
|
+
*
|
|
98
|
+
* It does NOT widen what an applicant can submit, which is the objection to
|
|
99
|
+
* check before extending this list: `Document` is already the last fallback,
|
|
100
|
+
* so a generic ID document has always qualified. Excluding only the BACK of
|
|
101
|
+
* one was an asymmetry, not a guard. Nothing here classifies the document —
|
|
102
|
+
* that is the backend's job — and auto-capture is assistance, not enforcement
|
|
103
|
+
* (#345): the cost of a wrong label is a well-framed photo of the wrong page,
|
|
104
|
+
* which is exactly what the manual shutter produces today.
|
|
105
|
+
*
|
|
106
|
+
* Order matters and this goes LAST: priority is by label, so `POA` still wins
|
|
107
|
+
* whenever it clears the floor, and this only decides frames that would
|
|
108
|
+
* otherwise have had no target at all.
|
|
109
|
+
*/
|
|
110
|
+
export const POA_TARGET_LABELS = [
|
|
111
|
+
'POA',
|
|
112
|
+
'Single page',
|
|
113
|
+
'Document',
|
|
114
|
+
'Document back',
|
|
115
|
+
];
|
|
116
|
+
/**
|
|
117
|
+
* Every gate the loop can fail, in the provisional precedence order the
|
|
118
|
+
* overlay renders them in.
|
|
119
|
+
*
|
|
120
|
+
* `tooClose` and `tooFar` are the two sides of #343's one window and cannot
|
|
121
|
+
* both fire; `tooClose` leads because "move back" is what the AMEX failure
|
|
122
|
+
* needs. Stability and focus sit last because they are meaningless until the
|
|
123
|
+
* sheet is framed — and #344 made `outOfFocus`-last a REQUIREMENT rather than
|
|
124
|
+
* a preference: focus is only computed on a frame that already has a box, and
|
|
125
|
+
* the score is non-monotonic, recovering at severe blur.
|
|
126
|
+
*
|
|
127
|
+
* Ruled by #345. `notStable` sits ABOVE `outOfFocus`, reversing the earlier
|
|
128
|
+
* provisional order, on #383's finding that sub-0.5 focus frames carry REAL
|
|
129
|
+
* motion (box IoU 0.910 vs 0.967, detection 0.664 vs 0.738): on paper a focus
|
|
130
|
+
* failure IS a motion failure, so "hold still" is the instruction that fixes
|
|
131
|
+
* it and "out of focus" is a paraphrase the applicant cannot act on
|
|
132
|
+
* differently. It also matches `idCapture`, which ends NOT_STABLE ->
|
|
133
|
+
* OUT_OF_FOCUS.
|
|
134
|
+
*
|
|
135
|
+
* `outOfFocus`-last is additionally STRUCTURAL, not a preference:
|
|
136
|
+
* `focusThresholdMet` initialises `false` and is only assigned inside the
|
|
137
|
+
* good-frame branch, so promoting focus up the ladder would report "out of
|
|
138
|
+
* focus" on frames where focus was never measured.
|
|
139
|
+
*
|
|
140
|
+
* `noDocument` and `tooFar` stay separate codes even though they always
|
|
141
|
+
* co-fire — an empty fill window returns `tooFar: true` by design, because the
|
|
142
|
+
* hard detection floor makes "no box" the far end of the range rather than an
|
|
143
|
+
* error. Distinct codes cost nothing and give the capture metadata a real
|
|
144
|
+
* distinction; they deliberately do NOT share a string (#346).
|
|
145
|
+
*/
|
|
146
|
+
export const POA_GATE_ORDER = [
|
|
147
|
+
'noDocument',
|
|
148
|
+
'tooClose',
|
|
149
|
+
'tooFar',
|
|
150
|
+
'notStable',
|
|
151
|
+
'outOfFocus',
|
|
152
|
+
];
|
|
153
|
+
/**
|
|
154
|
+
* The rectangle the applicant is actually asked to fill.
|
|
155
|
+
*
|
|
156
|
+
* This is the largest CENTRED sub-rect of the camera frame matching the guide
|
|
157
|
+
* box's aspect ratio, and gating on it rather than on the raw frame is the
|
|
158
|
+
* whole point:
|
|
159
|
+
*
|
|
160
|
+
* - Under `snapToGuides` (the default) the feed is sized to the guide rect
|
|
161
|
+
* under `object-fit: cover`, so this IS the pixels on screen. On a 9:16
|
|
162
|
+
* phone at A4 that is 100% of frame width by 79.5% of height; on a 16:9
|
|
163
|
+
* webcam it is 39.8% of WIDTH by 100% of height.
|
|
164
|
+
* - Under `fullscreen` the guide box is drawn inside a full-bleed feed, so
|
|
165
|
+
* this is a close approximation of it rather than exactly it — still far
|
|
166
|
+
* better than grading the whole frame.
|
|
167
|
+
*
|
|
168
|
+
* Grading the raw frame instead made `max(fillWidth, fillHeight)` pick the
|
|
169
|
+
* axis the applicant does not control on any landscape camera: a sheet filling
|
|
170
|
+
* a portrait guide box read `fillHeight ≈ 0.98` and passed, while
|
|
171
|
+
* `fillWidth ≈ 0.49` — half the capture being background — was never looked at.
|
|
172
|
+
* It also meant the submitted image contained pixels the applicant never saw.
|
|
173
|
+
*
|
|
174
|
+
* With no `aspectRatio` there is no guide to fill, so the frame is the rect.
|
|
175
|
+
*/
|
|
176
|
+
export function computeGuideRect(frameWidth, frameHeight, aspectRatio) {
|
|
177
|
+
const frame = { x: 0, y: 0, width: frameWidth, height: frameHeight };
|
|
178
|
+
if (frameWidth <= 0 ||
|
|
179
|
+
frameHeight <= 0 ||
|
|
180
|
+
!aspectRatio ||
|
|
181
|
+
!Number.isFinite(aspectRatio) ||
|
|
182
|
+
aspectRatio <= 0) {
|
|
183
|
+
return frame;
|
|
184
|
+
}
|
|
185
|
+
const frameAspect = frameWidth / frameHeight;
|
|
186
|
+
// Guide narrower than the frame -> height binds and the sides are cropped.
|
|
187
|
+
const width = aspectRatio < frameAspect ? frameHeight * aspectRatio : frameWidth;
|
|
188
|
+
const height = aspectRatio < frameAspect ? frameHeight : frameWidth / aspectRatio;
|
|
189
|
+
return {
|
|
190
|
+
x: (frameWidth - width) / 2,
|
|
191
|
+
y: (frameHeight - height) / 2,
|
|
192
|
+
width,
|
|
193
|
+
height,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Measure a detection box against the guide rect.
|
|
198
|
+
*
|
|
199
|
+
* Margins and fills are fractions OF THE GUIDE RECT, so a sheet wider than the
|
|
200
|
+
* guide reads `fill > 1` and a sheet spilling past an edge reads a NEGATIVE
|
|
201
|
+
* margin. Both are wanted: they are what makes "it does not fit in the box"
|
|
202
|
+
* trip `FILL_MAX` instead of quietly passing.
|
|
203
|
+
*/
|
|
204
|
+
export function computePoaFraming(box, rect) {
|
|
205
|
+
// A zero-sized rect yields no meaningful ratio. Report zeroes rather than
|
|
206
|
+
// emitting Infinity/NaN into the overlay; `fill: 0` fails `FILL_MIN` on its
|
|
207
|
+
// own, so the frame is rejected without a special case.
|
|
208
|
+
if (rect.width <= 0 || rect.height <= 0) {
|
|
209
|
+
return {
|
|
210
|
+
leftMargin: 0,
|
|
211
|
+
rightMargin: 0,
|
|
212
|
+
topMargin: 0,
|
|
213
|
+
bottomMargin: 0,
|
|
214
|
+
minMargin: 0,
|
|
215
|
+
fill: 0,
|
|
216
|
+
fillWidth: 0,
|
|
217
|
+
fillHeight: 0,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const leftMargin = (box.xMin - rect.x) / rect.width;
|
|
221
|
+
const rightMargin = (rect.x + rect.width - box.xMax) / rect.width;
|
|
222
|
+
const topMargin = (box.yMin - rect.y) / rect.height;
|
|
223
|
+
const bottomMargin = (rect.y + rect.height - box.yMax) / rect.height;
|
|
224
|
+
const minMargin = Math.min(leftMargin, rightMargin, topMargin, bottomMargin);
|
|
225
|
+
const fillWidth = box.width / rect.width;
|
|
226
|
+
const fillHeight = box.height / rect.height;
|
|
227
|
+
const fill = Math.max(fillWidth, fillHeight);
|
|
228
|
+
return {
|
|
229
|
+
leftMargin,
|
|
230
|
+
rightMargin,
|
|
231
|
+
topMargin,
|
|
232
|
+
bottomMargin,
|
|
233
|
+
minMargin,
|
|
234
|
+
fill,
|
|
235
|
+
fillWidth,
|
|
236
|
+
fillHeight,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Aggregate a window of `fill` readings, newest first, and take the verdict.
|
|
241
|
+
*
|
|
242
|
+
* The verdict is taken on however many frames are present rather than waiting
|
|
243
|
+
* for a full window: the window fills in under a second, and `notStable`
|
|
244
|
+
* already holds the capture until the IoU window is complete, so a second
|
|
245
|
+
* "not enough frames" state would only be a way for the two to disagree.
|
|
246
|
+
*/
|
|
247
|
+
export function computePoaFillWindow(fills, options) {
|
|
248
|
+
const { fillMin, fillMax } = options;
|
|
249
|
+
const framesNeeded = options.framesNeeded ?? fills.length;
|
|
250
|
+
if (fills.length === 0) {
|
|
251
|
+
return {
|
|
252
|
+
mean: 0,
|
|
253
|
+
instant: 0,
|
|
254
|
+
min: 0,
|
|
255
|
+
max: 0,
|
|
256
|
+
spread: 0,
|
|
257
|
+
framesTracked: 0,
|
|
258
|
+
framesNeeded,
|
|
259
|
+
fillMin,
|
|
260
|
+
fillMax,
|
|
261
|
+
// No box is the FAR end of the range, not an error state: #342 found a
|
|
262
|
+
// hard detection floor at 0.40 linear scale, past which the model emits
|
|
263
|
+
// nothing at all.
|
|
264
|
+
tooClose: false,
|
|
265
|
+
tooFar: true,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
let sum = 0;
|
|
269
|
+
let min = fills[0];
|
|
270
|
+
let max = fills[0];
|
|
271
|
+
for (const fill of fills) {
|
|
272
|
+
sum += fill;
|
|
273
|
+
if (fill < min)
|
|
274
|
+
min = fill;
|
|
275
|
+
if (fill > max)
|
|
276
|
+
max = fill;
|
|
277
|
+
}
|
|
278
|
+
const mean = sum / fills.length;
|
|
279
|
+
return {
|
|
280
|
+
mean,
|
|
281
|
+
instant: fills[0],
|
|
282
|
+
min,
|
|
283
|
+
max,
|
|
284
|
+
spread: max - min,
|
|
285
|
+
framesTracked: fills.length,
|
|
286
|
+
framesNeeded,
|
|
287
|
+
fillMin,
|
|
288
|
+
fillMax,
|
|
289
|
+
tooClose: mean > fillMax,
|
|
290
|
+
tooFar: mean < fillMin,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Peak score per emitted label.
|
|
295
|
+
*
|
|
296
|
+
* Keyed by the label STRING the model emitted rather than by a fixed set of
|
|
297
|
+
* per-class fields (IdCapture's `idCardFrontDetectionScore` &c.), so a class
|
|
298
|
+
* the map has not learned yet still shows up — as `class_23` if #354's export
|
|
299
|
+
* lands before the label map does. #341: this is why the still-open class
|
|
300
|
+
* question (#339) cannot ripple into the overlay's field list.
|
|
301
|
+
*/
|
|
302
|
+
export function peakScoresByLabel(detectedObjects) {
|
|
303
|
+
const scores = {};
|
|
304
|
+
for (const obj of detectedObjects) {
|
|
305
|
+
const previous = scores[obj.label];
|
|
306
|
+
if (previous === undefined || obj.score > previous) {
|
|
307
|
+
scores[obj.label] = obj.score;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return scores;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Pick the box the framing geometry is measured on: the highest-scoring box
|
|
314
|
+
* carrying the first label in `labels` that has any candidate above
|
|
315
|
+
* `minScore`. Priority is by LABEL, not by score, so a stray high-confidence
|
|
316
|
+
* `Document` on a POA sheet cannot displace the POA box.
|
|
317
|
+
*/
|
|
318
|
+
export function selectPoaTarget(detectedObjects, labels = POA_TARGET_LABELS, minScore = POA_MIN_SCORE) {
|
|
319
|
+
for (const label of labels) {
|
|
320
|
+
let best = null;
|
|
321
|
+
for (const obj of detectedObjects) {
|
|
322
|
+
if (obj.label !== label)
|
|
323
|
+
continue;
|
|
324
|
+
if (obj.score < minScore)
|
|
325
|
+
continue;
|
|
326
|
+
if (obj.box.width <= 0 || obj.box.height <= 0)
|
|
327
|
+
continue;
|
|
328
|
+
if (!best || obj.score > best.score)
|
|
329
|
+
best = obj;
|
|
330
|
+
}
|
|
331
|
+
if (best)
|
|
332
|
+
return { label: best.label, score: best.score, box: best.box };
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Every failing gate, in `POA_GATE_ORDER`. All of them, not just the winner:
|
|
338
|
+
* a one-message ladder is what #345 decides, and the operator needs to see
|
|
339
|
+
* what else was true when it decided.
|
|
340
|
+
*
|
|
341
|
+
* A `null` focus verdict means the focus model is not loaded (or #344 rules it
|
|
342
|
+
* out as a gate) — an absent signal is not a failing one.
|
|
343
|
+
*/
|
|
344
|
+
/**
|
|
345
|
+
* The winning guidance code for this frame, or null when every gate passes.
|
|
346
|
+
*
|
|
347
|
+
* Exactly one code wins, and it is the first failure in `POA_GATE_ORDER`.
|
|
348
|
+
*/
|
|
349
|
+
export function winningPoaGate(inputs) {
|
|
350
|
+
return failingPoaGates(inputs)[0] ?? null;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Whether this frame satisfies every gate — the shutter's whole condition.
|
|
354
|
+
*
|
|
355
|
+
* Derived from `failingPoaGates` rather than re-tested, so the thing the
|
|
356
|
+
* shutter fires on and the thing the overlay renders cannot disagree (#345).
|
|
357
|
+
*
|
|
358
|
+
* Thin only on its face: a satisfied frame already implies `stabilityFrames`
|
|
359
|
+
* consecutive frames of IoU >= the stability threshold PLUS a `stabilityFrames`
|
|
360
|
+
* mean of `fill` — roughly 0.7 s of evidence at 17.3 fps. The gates' own
|
|
361
|
+
* windows ARE the accumulator, which is why no second integrator is stacked on
|
|
362
|
+
* top of them.
|
|
363
|
+
*/
|
|
364
|
+
export function isAutoCaptureSatisfied(inputs) {
|
|
365
|
+
return failingPoaGates(inputs).length === 0;
|
|
366
|
+
}
|
|
367
|
+
export function failingPoaGates(inputs) {
|
|
368
|
+
const failing = [];
|
|
369
|
+
if (!inputs.framing) {
|
|
370
|
+
failing.push('noDocument');
|
|
371
|
+
// Below the detection floor the sheet is genuinely too far away (#342:
|
|
372
|
+
// nothing at all is emitted at 0.30 linear scale), so "too far" rides
|
|
373
|
+
// along with "no document" rather than being unreportable. An empty window
|
|
374
|
+
// reports `tooFar` for the same reason, so this reads it rather than
|
|
375
|
+
// hard-coding a second copy of the rule.
|
|
376
|
+
}
|
|
377
|
+
if (inputs.fillWindow.tooClose)
|
|
378
|
+
failing.push('tooClose');
|
|
379
|
+
if (inputs.fillWindow.tooFar)
|
|
380
|
+
failing.push('tooFar');
|
|
381
|
+
return appendQualityGates(failing, inputs);
|
|
382
|
+
}
|
|
383
|
+
function appendQualityGates(failing, inputs) {
|
|
384
|
+
if (!inputs.isStable)
|
|
385
|
+
failing.push('notStable');
|
|
386
|
+
// Focus ABSENT is not a failing gate. A focus model that failed to load
|
|
387
|
+
// reports `null`, and the loop then captures on framing alone — defensible
|
|
388
|
+
// because focus rejects only 1.8% of otherwise-eligible frames and cannot
|
|
389
|
+
// catch the failure that matters (a sharp, unreadable, too-far sheet). The
|
|
390
|
+
// two arms stay separable in the field through `autoCaptureStatus`.
|
|
391
|
+
if (inputs.focusThresholdMet === false)
|
|
392
|
+
failing.push('outOfFocus');
|
|
393
|
+
return failing;
|
|
394
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type StabilizerState } from '../utils/stabilizer';
|
|
2
|
+
import { type PoaGate, type PoaGateInputs } from './autoCaptureGeometry';
|
|
3
|
+
/**
|
|
4
|
+
* What the pill says.
|
|
5
|
+
*
|
|
6
|
+
* `'none'` is the pre-first-frame value, mirroring `idCapture` and
|
|
7
|
+
* `selfieCapture`, which both initialise their stabilizer at NONE.
|
|
8
|
+
* `'holdStill'` is the single satisfied code.
|
|
9
|
+
*/
|
|
10
|
+
export type PoaGuidanceCode = 'none' | 'holdStill' | PoaGate;
|
|
11
|
+
export type PoaGuidanceState = StabilizerState<PoaGuidanceCode>;
|
|
12
|
+
/**
|
|
13
|
+
* Seeded one whole min-hold in the PAST, so the first real message is gated by
|
|
14
|
+
* the 250 ms debounce alone.
|
|
15
|
+
*
|
|
16
|
+
* `displayedAt: 0` reads like "long ago" and is not. The stabilizer is
|
|
17
|
+
* advanced with `timeRunning` — a clock that STARTS at zero — so `now -
|
|
18
|
+
* displayedAt >= minHoldMs` was `timeRunning >= 1800`, and the applicant got
|
|
19
|
+
* no instruction at all for the first 1.8 seconds of a capture. `idCapture`
|
|
20
|
+
* and `selfieCapture` initialise the same way and get away with it because
|
|
21
|
+
* they advance on a wall clock, where zero really is long ago.
|
|
22
|
+
*
|
|
23
|
+
* Derived from the constant rather than written as a literal: the two must not
|
|
24
|
+
* drift, since the whole point is that this is exactly one hold in the past.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createPoaGuidanceState(): PoaGuidanceState;
|
|
27
|
+
/**
|
|
28
|
+
* This frame's raw code, before stabilization.
|
|
29
|
+
*
|
|
30
|
+
* Derived from the same `failingPoaGates` call the shutter's predicate uses, so
|
|
31
|
+
* "what the applicant is told" and "whether it captured" cannot disagree about
|
|
32
|
+
* which gates passed.
|
|
33
|
+
*/
|
|
34
|
+
export declare function poaGuidanceCode(inputs: PoaGateInputs): PoaGuidanceCode;
|
|
35
|
+
/**
|
|
36
|
+
* Advance the displayed message by one frame.
|
|
37
|
+
*
|
|
38
|
+
* `now` is the frame's own `timeRunning`, not a clock read — the same reason
|
|
39
|
+
* the shutter takes its time from the frame.
|
|
40
|
+
*
|
|
41
|
+
* Accepted consequence, worth knowing before someone reports it as a bug: with
|
|
42
|
+
* a shutter that fires within ~1 s the sequence is `none` -> first real code at
|
|
43
|
+
* ~250 ms -> capture at ~1000 ms, so `holdStill` DOES NOT REACH THE SCREEN on a
|
|
44
|
+
* clean capture. The applicant's feedback is the review screen, not a 200 ms
|
|
45
|
+
* flash of green. `holdStill` still earns its place: it is what displays when a
|
|
46
|
+
* struggling applicant finally gets the framing right.
|
|
47
|
+
*/
|
|
48
|
+
export declare function advancePoaGuidance(state: PoaGuidanceState, inputs: PoaGateInputs, now: number): PoaGuidanceState;
|
|
49
|
+
/** What the overlay needs to tell "wrong threshold" from "stuck message". */
|
|
50
|
+
export type PoaGuidanceDiagnostics = {
|
|
51
|
+
/** This frame's ladder winner, before the debounce. */
|
|
52
|
+
raw: PoaGuidanceCode;
|
|
53
|
+
/** What is waiting out the 250 ms debounce. */
|
|
54
|
+
pendingCandidate: PoaGuidanceCode;
|
|
55
|
+
/** What is actually on screen. */
|
|
56
|
+
displayed: PoaGuidanceCode;
|
|
57
|
+
/** How long `displayed` has been up, ms. */
|
|
58
|
+
displayedForMs: number;
|
|
59
|
+
};
|
|
60
|
+
export declare function poaGuidanceDiagnostics(state: PoaGuidanceState, raw: PoaGuidanceCode, now: number): PoaGuidanceDiagnostics;
|
|
61
|
+
//# sourceMappingURL=autoCaptureGuidance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoCaptureGuidance.d.ts","sourceRoot":"","sources":["../../src/documentCapture/autoCaptureGuidance.ts"],"names":[],"mappings":"AAmBA,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,CAAA;AAE5D,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAA;AAE/D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe,CAItE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,MAAM,GACV,gBAAgB,CAElB;AAED,6EAA6E;AAC7E,MAAM,MAAM,sBAAsB,GAAG;IACnC,uDAAuD;IACvD,GAAG,EAAE,eAAe,CAAA;IACpB,+CAA+C;IAC/C,gBAAgB,EAAE,eAAe,CAAA;IACjC,kCAAkC;IAClC,SAAS,EAAE,eAAe,CAAA;IAC1B,4CAA4C;IAC5C,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,EACvB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,MAAM,GACV,sBAAsB,CAOxB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The guidance ladder's rendered half (#345, #346).
|
|
2
|
+
//
|
|
3
|
+
// The ladder produces one code per frame; this routes it through the shared
|
|
4
|
+
// stabilizer before anything renders it.
|
|
5
|
+
//
|
|
6
|
+
// THE ROUTING IS LOAD-BEARING, NOT PLUMBING. #383's ruling that focus needs no
|
|
7
|
+
// hold, no hysteresis and no aggregation is correct ONLY because the focus
|
|
8
|
+
// excursions are 1-3 frames — measured at [55, 56, 56, 57, 57, 57, 59, 59, 59,
|
|
9
|
+
// 59, 61, 61, 61, 114, 114, 119, 171, 174] ms, longest 174 ms — and 0 of 18
|
|
10
|
+
// reach the 250 ms debounce. A ladder that renders the raw per-frame verdict
|
|
11
|
+
// re-opens #383 immediately, AND IT WILL PRESENT AS A THRESHOLD PROBLEM WHEN IT
|
|
12
|
+
// IS A PLUMBING ONE.
|
|
13
|
+
//
|
|
14
|
+
// Corollary the implementation must preserve: the stabilizer governs the
|
|
15
|
+
// MESSAGE, never the SHUTTER. The shutter reads live gates, so a capture can
|
|
16
|
+
// fire while a stale "Move back" is still on screen. That is `idCapture`'s
|
|
17
|
+
// shipped behaviour — guidance is display-only, deliberately downstream of the
|
|
18
|
+
// good-frame test — not a POA wart.
|
|
19
|
+
import { createStabilizerState, stabilizeStep, MESSAGE_MIN_HOLD_MS, } from '../utils/stabilizer';
|
|
20
|
+
import { isAutoCaptureSatisfied, winningPoaGate, } from './autoCaptureGeometry';
|
|
21
|
+
/**
|
|
22
|
+
* Seeded one whole min-hold in the PAST, so the first real message is gated by
|
|
23
|
+
* the 250 ms debounce alone.
|
|
24
|
+
*
|
|
25
|
+
* `displayedAt: 0` reads like "long ago" and is not. The stabilizer is
|
|
26
|
+
* advanced with `timeRunning` — a clock that STARTS at zero — so `now -
|
|
27
|
+
* displayedAt >= minHoldMs` was `timeRunning >= 1800`, and the applicant got
|
|
28
|
+
* no instruction at all for the first 1.8 seconds of a capture. `idCapture`
|
|
29
|
+
* and `selfieCapture` initialise the same way and get away with it because
|
|
30
|
+
* they advance on a wall clock, where zero really is long ago.
|
|
31
|
+
*
|
|
32
|
+
* Derived from the constant rather than written as a literal: the two must not
|
|
33
|
+
* drift, since the whole point is that this is exactly one hold in the past.
|
|
34
|
+
*/
|
|
35
|
+
export function createPoaGuidanceState() {
|
|
36
|
+
return createStabilizerState('none', -MESSAGE_MIN_HOLD_MS);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* This frame's raw code, before stabilization.
|
|
40
|
+
*
|
|
41
|
+
* Derived from the same `failingPoaGates` call the shutter's predicate uses, so
|
|
42
|
+
* "what the applicant is told" and "whether it captured" cannot disagree about
|
|
43
|
+
* which gates passed.
|
|
44
|
+
*/
|
|
45
|
+
export function poaGuidanceCode(inputs) {
|
|
46
|
+
return isAutoCaptureSatisfied(inputs)
|
|
47
|
+
? 'holdStill'
|
|
48
|
+
: (winningPoaGate(inputs) ?? 'holdStill');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Advance the displayed message by one frame.
|
|
52
|
+
*
|
|
53
|
+
* `now` is the frame's own `timeRunning`, not a clock read — the same reason
|
|
54
|
+
* the shutter takes its time from the frame.
|
|
55
|
+
*
|
|
56
|
+
* Accepted consequence, worth knowing before someone reports it as a bug: with
|
|
57
|
+
* a shutter that fires within ~1 s the sequence is `none` -> first real code at
|
|
58
|
+
* ~250 ms -> capture at ~1000 ms, so `holdStill` DOES NOT REACH THE SCREEN on a
|
|
59
|
+
* clean capture. The applicant's feedback is the review screen, not a 200 ms
|
|
60
|
+
* flash of green. `holdStill` still earns its place: it is what displays when a
|
|
61
|
+
* struggling applicant finally gets the framing right.
|
|
62
|
+
*/
|
|
63
|
+
export function advancePoaGuidance(state, inputs, now) {
|
|
64
|
+
return stabilizeStep(state, poaGuidanceCode(inputs), now);
|
|
65
|
+
}
|
|
66
|
+
export function poaGuidanceDiagnostics(state, raw, now) {
|
|
67
|
+
return {
|
|
68
|
+
raw,
|
|
69
|
+
pendingCandidate: state.pendingCandidate,
|
|
70
|
+
displayed: state.displayed,
|
|
71
|
+
displayedForMs: Math.max(0, now - state.displayedAt),
|
|
72
|
+
};
|
|
73
|
+
}
|