@idmission/websdk-core 0.2.0 → 0.6.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 +19 -0
- package/dist/attestation/clientAttestation.d.ts +5 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -1
- package/dist/attestation/clientAttestation.js +4 -4
- package/dist/attestation/collectClientAttestation.d.ts +3 -1
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -1
- package/dist/attestation/collectClientAttestation.js +4 -3
- package/dist/camera/acquireCamera.d.ts +5 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -1
- package/dist/camera/acquireCamera.js +25 -5
- package/dist/captureProgress/actor.d.ts +30 -0
- package/dist/captureProgress/actor.d.ts.map +1 -0
- package/dist/captureProgress/actor.js +754 -0
- package/dist/captureProgress/encoder.d.ts +7 -0
- package/dist/captureProgress/encoder.d.ts.map +1 -0
- package/dist/captureProgress/encoder.js +195 -0
- package/dist/captureProgress/index.d.ts +4 -0
- package/dist/captureProgress/index.d.ts.map +1 -0
- package/dist/captureProgress/index.js +45 -0
- package/dist/captureProgress/internal.d.ts +3 -0
- package/dist/captureProgress/internal.d.ts.map +1 -0
- package/dist/captureProgress/internal.js +1 -0
- package/dist/captureProgress/protocol.d.ts +224 -0
- package/dist/captureProgress/protocol.d.ts.map +1 -0
- package/dist/captureProgress/protocol.js +106 -0
- package/dist/captureProgress/recorder.d.ts +32 -0
- package/dist/captureProgress/recorder.d.ts.map +1 -0
- package/dist/captureProgress/recorder.js +554 -0
- package/dist/captureProgress/transport.d.ts +33 -0
- package/dist/captureProgress/transport.d.ts.map +1 -0
- package/dist/captureProgress/transport.js +109 -0
- package/dist/captureProgress/types.d.ts +35 -0
- package/dist/captureProgress/types.d.ts.map +1 -0
- package/dist/captureProgress/types.js +27 -0
- package/dist/client/IdmissionClient.d.ts +88 -18
- package/dist/client/IdmissionClient.d.ts.map +1 -1
- package/dist/client/IdmissionClient.js +241 -105
- package/dist/client/approval.d.ts +15 -0
- package/dist/client/approval.d.ts.map +1 -0
- package/dist/client/approval.js +19 -0
- package/dist/client/artifacts.d.ts +20 -0
- package/dist/client/artifacts.d.ts.map +1 -1
- package/dist/client/documentFileMetadata.d.ts +13 -0
- package/dist/client/documentFileMetadata.d.ts.map +1 -0
- package/dist/client/documentFileMetadata.js +51 -0
- package/dist/client/index.d.ts +4 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- package/dist/client/payload.d.ts +3 -0
- package/dist/client/payload.d.ts.map +1 -1
- package/dist/client/payload.js +1 -0
- package/dist/client/submissionMetadata.d.ts +4 -1
- package/dist/client/submissionMetadata.d.ts.map +1 -1
- package/dist/client/submissionMetadata.js +13 -8
- package/dist/client/types.d.ts +6 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/validateSession.d.ts +2 -0
- package/dist/client/validateSession.d.ts.map +1 -1
- package/dist/client/validateSession.js +53 -24
- package/dist/documentCapture/autoCaptureEngine.d.ts.map +1 -1
- package/dist/documentCapture/autoCaptureEngine.js +27 -8
- package/dist/documentCapture/autoCaptureGeometry.d.ts +97 -7
- package/dist/documentCapture/autoCaptureGeometry.d.ts.map +1 -1
- package/dist/documentCapture/autoCaptureGeometry.js +87 -6
- package/dist/documentCapture/autoCaptureMetadata.d.ts +12 -4
- package/dist/documentCapture/autoCaptureMetadata.d.ts.map +1 -1
- package/dist/documentCapture/autoCaptureMetadata.js +8 -5
- package/dist/documentCapture/autoCaptureOptions.d.ts +4 -5
- package/dist/documentCapture/autoCaptureOptions.d.ts.map +1 -1
- package/dist/documentCapture/autoCaptureOptions.js +4 -5
- package/dist/documentCapture/controller.d.ts +5 -0
- package/dist/documentCapture/controller.d.ts.map +1 -1
- package/dist/documentCapture/controller.js +37 -21
- package/dist/documentCapture/index.d.ts +1 -1
- package/dist/documentCapture/index.d.ts.map +1 -1
- package/dist/documentCapture/index.js +1 -1
- package/dist/idCapture/controller.d.ts +4 -1
- package/dist/idCapture/controller.d.ts.map +1 -1
- package/dist/idCapture/controller.js +69 -10
- package/dist/idCapture/state.d.ts +1 -3
- package/dist/idCapture/state.d.ts.map +1 -1
- package/dist/idCapture/submit.d.ts.map +1 -1
- package/dist/idCapture/submit.js +35 -1
- package/dist/idCapture/types.d.ts +2 -0
- package/dist/idCapture/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/liveness/challengeGeometry.d.ts +48 -17
- package/dist/liveness/challengeGeometry.d.ts.map +1 -1
- package/dist/liveness/challengeGeometry.js +101 -54
- package/dist/models/DocumentDetection.d.ts.map +1 -1
- package/dist/models/DocumentDetection.js +38 -2
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +2 -2
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -1
- package/dist/models/defaults/DocumentDetectorLiteRT.js +27 -2
- package/dist/models/defaults/HandLandmarkLiteRT.d.ts +3 -0
- package/dist/models/defaults/HandLandmarkLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/HandLandmarkLiteRT.js +5 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.d.ts +3 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/IrisLandmarkLiteRT.js +5 -0
- package/dist/models/defaults/PalmDetectionLiteRT.d.ts +3 -0
- package/dist/models/defaults/PalmDetectionLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/PalmDetectionLiteRT.js +5 -0
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts +2 -2
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts.map +1 -1
- package/dist/models/defaults/PoaDocumentDetectorLiteRT.js +12 -8
- package/dist/models/defaults/index.d.ts +10 -1
- package/dist/models/defaults/index.d.ts.map +1 -1
- package/dist/models/defaults/index.js +12 -0
- package/dist/models/preloadModels.d.ts +4 -3
- package/dist/models/preloadModels.d.ts.map +1 -1
- package/dist/models/preloadModels.js +23 -3
- package/dist/models/providers/litert/FaceLandmarker.d.ts +8 -1
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -1
- package/dist/models/providers/litert/FaceLandmarker.js +95 -3
- package/dist/models/providers/litert/HandOverFaceDetector.d.ts +27 -0
- package/dist/models/providers/litert/HandOverFaceDetector.d.ts.map +1 -0
- package/dist/models/providers/litert/HandOverFaceDetector.js +162 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +4 -2
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -1
- package/dist/models/providers/litert/docDetectPrePost.js +17 -5
- package/dist/models/providers/litert/handLandmarkPrePost.d.ts +20 -0
- package/dist/models/providers/litert/handLandmarkPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/handLandmarkPrePost.js +72 -0
- package/dist/models/providers/litert/handOverFace.d.ts +44 -0
- package/dist/models/providers/litert/handOverFace.d.ts.map +1 -0
- package/dist/models/providers/litert/handOverFace.js +139 -0
- package/dist/models/providers/litert/irisPrePost.d.ts +38 -0
- package/dist/models/providers/litert/irisPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/irisPrePost.js +101 -0
- package/dist/models/providers/litert/palmPrePost.d.ts +55 -0
- package/dist/models/providers/litert/palmPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/palmPrePost.js +151 -0
- package/dist/sdkVersions.d.ts +18 -0
- package/dist/sdkVersions.d.ts.map +1 -0
- package/dist/sdkVersions.js +8 -0
- package/dist/selfieCapture/captureQuality.d.ts +43 -0
- package/dist/selfieCapture/captureQuality.d.ts.map +1 -0
- package/dist/selfieCapture/captureQuality.js +87 -0
- package/dist/selfieCapture/challengeRunner.d.ts +9 -2
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -1
- package/dist/selfieCapture/challengeRunner.js +2 -5
- package/dist/selfieCapture/controller.d.ts +62 -1
- package/dist/selfieCapture/controller.d.ts.map +1 -1
- package/dist/selfieCapture/controller.js +470 -105
- package/dist/selfieCapture/faceTracking.d.ts +69 -1
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -1
- package/dist/selfieCapture/faceTracking.js +134 -6
- package/dist/selfieCapture/guidance.d.ts +15 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -1
- package/dist/selfieCapture/guidance.js +23 -0
- package/dist/selfieCapture/index.d.ts +3 -2
- package/dist/selfieCapture/index.d.ts.map +1 -1
- package/dist/selfieCapture/index.js +1 -1
- package/dist/selfieCapture/livenessMachine.d.ts +2 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -1
- package/dist/selfieCapture/livenessMachine.js +8 -0
- package/dist/selfieCapture/pipeline.d.ts +8 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -1
- package/dist/selfieCapture/pipeline.js +2 -2
- package/dist/selfieCapture/reducer.d.ts +7 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -1
- package/dist/selfieCapture/reducer.js +45 -4
- package/dist/selfieCapture/state.d.ts +6 -0
- package/dist/selfieCapture/state.d.ts.map +1 -1
- package/dist/selfieCapture/state.js +1 -0
- package/dist/signature/frameDecode.d.ts.map +1 -1
- package/dist/signature/frameDecode.js +29 -0
- package/dist/signature/metadata.d.ts +10 -1
- package/dist/signature/metadata.d.ts.map +1 -1
- package/dist/signature/quality.d.ts +14 -6
- package/dist/signature/quality.d.ts.map +1 -1
- package/dist/signature/quality.js +13 -4
- package/dist/signatureCapture/controller.d.ts +2 -1
- package/dist/signatureCapture/controller.d.ts.map +1 -1
- package/dist/signatureCapture/controller.js +47 -2
- package/dist/signatureCapture/pipeline.d.ts.map +1 -1
- package/dist/signatureCapture/pipeline.js +6 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Hand-over-face signal for the palm-detection occlusion experiment
|
|
2
|
+
// (docs/research/palm-detection-occlusion.md §3).
|
|
3
|
+
//
|
|
4
|
+
// Palm detection boxes the palm/back of the hand, not the hand, so fingers
|
|
5
|
+
// pressed over a mouth or eyes sit outside the box. The box is grown into a
|
|
6
|
+
// hand region along the wrist → middle-MCP direction, the same orientation
|
|
7
|
+
// MediaPipe builds its hand ROI from; MediaPipe's ROI is a 2.6× square because
|
|
8
|
+
// it is a landmark crop with margin, a gate wants the hand itself.
|
|
9
|
+
//
|
|
10
|
+
// Coverage alone decides. Doc 10 also asked for the palm centre to sit inside
|
|
11
|
+
// the face box grown 25%, against phone-to-ear false positives, but a hand
|
|
12
|
+
// over the mouth or chin puts its palm BELOW the face with only the fingers on
|
|
13
|
+
// it — the guard rejected exactly that pose on a live camera. A hand beside
|
|
14
|
+
// the face with its fingers up does not overlap the face box, so the coverage
|
|
15
|
+
// threshold already covers the phone-to-ear case.
|
|
16
|
+
import { PALM_MIDDLE_MCP, PALM_WRIST } from './palmPrePost';
|
|
17
|
+
// Hand region in palm-box sides: 1.3 wide, 2 long (palm + fingers), centred
|
|
18
|
+
// half a palm toward the fingers.
|
|
19
|
+
const HAND_WIDTH = 1.3;
|
|
20
|
+
const HAND_LENGTH = 2;
|
|
21
|
+
const FINGER_SHIFT = 0.5;
|
|
22
|
+
// The face box is the 468-point mesh's bbox, which stops mid-forehead, so a
|
|
23
|
+
// hand resting on the hair covered nothing it measured. Published head
|
|
24
|
+
// measurements put the skull top 0.38 face-box heights above the box for the
|
|
25
|
+
// average man and 0.46 for the average woman (MediaPipe's canonical mesh scaled
|
|
26
|
+
// to adult eye-corner distances); hair tops on one live webcam sat 0.34–0.43.
|
|
27
|
+
// 0.45 reaches the average woman's skull — a box a little high on a man only
|
|
28
|
+
// counts a hand hovering just above his head, the rarer mistake.
|
|
29
|
+
export const DEFAULT_HEAD_EXTENSION = 0.45;
|
|
30
|
+
export const DEFAULT_HAND_COVERAGE_THRESHOLD = 0.1;
|
|
31
|
+
/**
|
|
32
|
+
* `palms` in frame [0, 1] coordinates (`decodePalms`), `face` in frame pixels
|
|
33
|
+
* (`Face.box`). Pass the variant-B `crop` (frame pixels) so a palm whose wrist
|
|
34
|
+
* fell outside it keeps its un-extended box — the orientation estimate needs
|
|
35
|
+
* the wrist keypoint, which a crop can cut off.
|
|
36
|
+
*/
|
|
37
|
+
export function measureHandOverFace(palms, face, frame, options = {}) {
|
|
38
|
+
const threshold = options.threshold ?? DEFAULT_HAND_COVERAGE_THRESHOLD;
|
|
39
|
+
const head = headBox(face, options.headExtension);
|
|
40
|
+
const headArea = (head.xMax - head.xMin) * (head.yMax - head.yMin);
|
|
41
|
+
let best = { coverage: 0, handOverFace: false, region: null, score: null };
|
|
42
|
+
if (headArea <= 0)
|
|
43
|
+
return best;
|
|
44
|
+
for (const palm of palms) {
|
|
45
|
+
const toPx = (p) => ({ x: p.x * frame.width, y: p.y * frame.height });
|
|
46
|
+
const min = toPx({ x: palm.xMin, y: palm.yMin });
|
|
47
|
+
const max = toPx({ x: palm.xMax, y: palm.yMax });
|
|
48
|
+
const centre = { x: (min.x + max.x) / 2, y: (min.y + max.y) / 2 };
|
|
49
|
+
const wrist = toPx(palm.keypoints[PALM_WRIST]);
|
|
50
|
+
const mcp = toPx(palm.keypoints[PALM_MIDDLE_MCP]);
|
|
51
|
+
const wristCut = options.crop !== undefined && !inside(wrist, options.crop);
|
|
52
|
+
const region = wristCut
|
|
53
|
+
? boxCorners({ xMin: min.x, yMin: min.y, xMax: max.x, yMax: max.y })
|
|
54
|
+
: handRegion(centre, Math.max(max.x - min.x, max.y - min.y), wrist, mcp);
|
|
55
|
+
const coverage = polygonArea(clipToBox(region, head)) / headArea;
|
|
56
|
+
if (best.region === null || coverage > best.coverage) {
|
|
57
|
+
best = { coverage, handOverFace: coverage > threshold, region, score: palm.score };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return best;
|
|
61
|
+
}
|
|
62
|
+
function handRegion(centre, side, wrist, mcp) {
|
|
63
|
+
const dx = mcp.x - wrist.x;
|
|
64
|
+
const dy = mcp.y - wrist.y;
|
|
65
|
+
const len = Math.hypot(dx, dy);
|
|
66
|
+
// Degenerate keypoints: assume an upright hand (fingers up in the image).
|
|
67
|
+
const u = len > 1e-6 ? { x: dx / len, y: dy / len } : { x: 0, y: -1 };
|
|
68
|
+
const v = { x: -u.y, y: u.x };
|
|
69
|
+
const c = { x: centre.x + FINGER_SHIFT * side * u.x, y: centre.y + FINGER_SHIFT * side * u.y };
|
|
70
|
+
const hl = (HAND_LENGTH * side) / 2;
|
|
71
|
+
const hw = (HAND_WIDTH * side) / 2;
|
|
72
|
+
return [
|
|
73
|
+
{ x: c.x + hl * u.x + hw * v.x, y: c.y + hl * u.y + hw * v.y },
|
|
74
|
+
{ x: c.x + hl * u.x - hw * v.x, y: c.y + hl * u.y - hw * v.y },
|
|
75
|
+
{ x: c.x - hl * u.x - hw * v.x, y: c.y - hl * u.y - hw * v.y },
|
|
76
|
+
{ x: c.x - hl * u.x + hw * v.x, y: c.y - hl * u.y + hw * v.y },
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The region coverage is measured on: the face box extended upward over the
|
|
81
|
+
* forehead and hair by `extension` face heights, clamped to the top of the frame.
|
|
82
|
+
*/
|
|
83
|
+
export function headBox(face, extension = DEFAULT_HEAD_EXTENSION) {
|
|
84
|
+
const yMin = Math.max(0, face.yMin - extension * (face.yMax - face.yMin));
|
|
85
|
+
return { xMin: face.xMin, yMin, xMax: face.xMax, yMax: face.yMax };
|
|
86
|
+
}
|
|
87
|
+
/** `b` scaled by `s` about its centre. */
|
|
88
|
+
export function scaleBox(b, s) {
|
|
89
|
+
const gx = ((b.xMax - b.xMin) * (s - 1)) / 2;
|
|
90
|
+
const gy = ((b.yMax - b.yMin) * (s - 1)) / 2;
|
|
91
|
+
return { xMin: b.xMin - gx, yMin: b.yMin - gy, xMax: b.xMax + gx, yMax: b.yMax + gy };
|
|
92
|
+
}
|
|
93
|
+
function inside(p, b) {
|
|
94
|
+
return p.x >= b.xMin && p.x <= b.xMax && p.y >= b.yMin && p.y <= b.yMax;
|
|
95
|
+
}
|
|
96
|
+
function boxCorners(b) {
|
|
97
|
+
return [
|
|
98
|
+
{ x: b.xMin, y: b.yMin },
|
|
99
|
+
{ x: b.xMax, y: b.yMin },
|
|
100
|
+
{ x: b.xMax, y: b.yMax },
|
|
101
|
+
{ x: b.xMin, y: b.yMax },
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
// Sutherland–Hodgman against the box's four half-planes; the region is convex.
|
|
105
|
+
function clipToBox(polygon, b) {
|
|
106
|
+
const distances = [
|
|
107
|
+
(p) => p.x - b.xMin,
|
|
108
|
+
(p) => b.xMax - p.x,
|
|
109
|
+
(p) => p.y - b.yMin,
|
|
110
|
+
(p) => b.yMax - p.y,
|
|
111
|
+
];
|
|
112
|
+
let out = polygon;
|
|
113
|
+
for (const dist of distances) {
|
|
114
|
+
const input = out;
|
|
115
|
+
out = [];
|
|
116
|
+
for (let i = 0; i < input.length; i++) {
|
|
117
|
+
const a = input[i];
|
|
118
|
+
const c = input[(i + 1) % input.length];
|
|
119
|
+
const da = dist(a);
|
|
120
|
+
const dc = dist(c);
|
|
121
|
+
if (da >= 0)
|
|
122
|
+
out.push(a);
|
|
123
|
+
if (da >= 0 !== dc >= 0) {
|
|
124
|
+
const t = da / (da - dc);
|
|
125
|
+
out.push({ x: a.x + t * (c.x - a.x), y: a.y + t * (c.y - a.y) });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
function polygonArea(polygon) {
|
|
132
|
+
let twice = 0;
|
|
133
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
134
|
+
const a = polygon[i];
|
|
135
|
+
const c = polygon[(i + 1) % polygon.length];
|
|
136
|
+
twice += a.x * c.y - c.x * a.y;
|
|
137
|
+
}
|
|
138
|
+
return Math.abs(twice) / 2;
|
|
139
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const IRIS_INPUT_SIZE = 64;
|
|
2
|
+
/** Length of the eye-contour output tensor: 71 points x (x, y, z). */
|
|
3
|
+
export declare const EYE_CONTOUR_LENGTH: number;
|
|
4
|
+
type Point = {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
/** One eye as the iris model sees it. */
|
|
9
|
+
export type IrisEye = {
|
|
10
|
+
/** Mesh indices of the two corners the crop is built from. */
|
|
11
|
+
corners: readonly [number, number];
|
|
12
|
+
/** Mirror the crop (MediaPipe's IS_RIGHT_EYE). */
|
|
13
|
+
flip: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Mesh indices the first 16 contour points replace, in contour order: the
|
|
16
|
+
* lower lid corner to corner, then the upper lid between the corners.
|
|
17
|
+
*/
|
|
18
|
+
meshIndices: readonly number[];
|
|
19
|
+
};
|
|
20
|
+
export declare const IRIS_EYES: readonly IrisEye[];
|
|
21
|
+
/** A square eye crop in source-frame pixels, rotated to level the corners. */
|
|
22
|
+
export type EyeRoi = {
|
|
23
|
+
cx: number;
|
|
24
|
+
cy: number;
|
|
25
|
+
side: number;
|
|
26
|
+
angle: number;
|
|
27
|
+
flip: boolean;
|
|
28
|
+
};
|
|
29
|
+
export declare function eyeRoi(a: Point, b: Point, flip: boolean): EyeRoi;
|
|
30
|
+
/** Draws the eye's ROI from `source` into a 64x64 crop, as [0, 1] RGB. */
|
|
31
|
+
export declare function preprocessEye(source: HTMLVideoElement | HTMLCanvasElement, roi: EyeRoi): Float32Array;
|
|
32
|
+
/**
|
|
33
|
+
* Maps the first `count` contour points from crop pixels back to source-frame
|
|
34
|
+
* pixels: the inverse of preprocessEye's transform.
|
|
35
|
+
*/
|
|
36
|
+
export declare function projectEyeContour(contour: Float32Array, roi: EyeRoi, count: number): Point[];
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=irisPrePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"irisPrePost.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/litert/irisPrePost.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,eAAe,KAAK,CAAA;AACjC,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,QAAS,CAAA;AAGxC,KAAK,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC,yCAAyC;AACzC,MAAM,MAAM,OAAO,GAAG;IACpB,8DAA8D;IAC9D,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,kDAAkD;IAClD,IAAI,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CAC/B,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,SAAS,OAAO,EAiBvC,CAAA;AAED,8EAA8E;AAC9E,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,OAAO,CAAA;CACd,CAAA;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAQhE;AAgBD,0EAA0E;AAC1E,wBAAgB,aAAa,CAC3B,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,EAC5C,GAAG,EAAE,MAAM,GACV,YAAY,CAsBd;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,EACrB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,KAAK,EAAE,CAWT"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Pre/post-processing for MediaPipe's `iris_landmark.tflite`, run on each eye
|
|
2
|
+
// after the 468-point face mesh to sharpen its eye outlines.
|
|
3
|
+
//
|
|
4
|
+
// The hosted mesh (face_landmark.tflite) moves both eyelids together: a wink
|
|
5
|
+
// reads nearly as open as the open eye, so no eye-openness threshold on the
|
|
6
|
+
// mesh alone can see a single closed eye. MediaPipe's own pipeline solves this
|
|
7
|
+
// by running this model on a crop of each eye and writing its eyelid contour
|
|
8
|
+
// back over the mesh (update_face_landmarks_calculator.cc); this module is the
|
|
9
|
+
// geometry for that step.
|
|
10
|
+
//
|
|
11
|
+
// The contract comes from MediaPipe's graphs, not guesswork:
|
|
12
|
+
// - ROI (iris_landmark_landmarks_to_roi.pbtxt): a square 2.3x the span of
|
|
13
|
+
// the eye's two corner landmarks, rotated so the corners are level.
|
|
14
|
+
// - Input (iris_landmark_cpu.pbtxt): 64x64 RGB in [0, 1]
|
|
15
|
+
// (`zero_center: false`); the 362/263 eye is mirrored horizontally.
|
|
16
|
+
// - Output: 71 eye-contour points (x, y, z) in crop pixels, plus 5 iris
|
|
17
|
+
// points in a second tensor. The first 16 contour points are the eyelids.
|
|
18
|
+
export const IRIS_INPUT_SIZE = 64;
|
|
19
|
+
/** Length of the eye-contour output tensor: 71 points x (x, y, z). */
|
|
20
|
+
export const EYE_CONTOUR_LENGTH = 71 * 3;
|
|
21
|
+
const ROI_SCALE = 2.3;
|
|
22
|
+
export const IRIS_EYES = [
|
|
23
|
+
{
|
|
24
|
+
corners: [33, 133],
|
|
25
|
+
flip: false,
|
|
26
|
+
meshIndices: [
|
|
27
|
+
33, 7, 163, 144, 145, 153, 154, 155, 133, 246, 161, 160, 159, 158, 157,
|
|
28
|
+
173,
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
corners: [362, 263],
|
|
33
|
+
flip: true,
|
|
34
|
+
meshIndices: [
|
|
35
|
+
263, 249, 390, 373, 374, 380, 381, 382, 362, 466, 388, 387, 386, 385,
|
|
36
|
+
384, 398,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
export function eyeRoi(a, b, flip) {
|
|
41
|
+
return {
|
|
42
|
+
cx: (a.x + b.x) / 2,
|
|
43
|
+
cy: (a.y + b.y) / 2,
|
|
44
|
+
side: ROI_SCALE * Math.max(Math.abs(b.x - a.x), Math.abs(b.y - a.y)),
|
|
45
|
+
angle: Math.atan2(b.y - a.y, b.x - a.x),
|
|
46
|
+
flip,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
let cropCtx = null;
|
|
50
|
+
function getCropContext() {
|
|
51
|
+
if (!cropCtx) {
|
|
52
|
+
const canvas = document.createElement('canvas');
|
|
53
|
+
canvas.width = IRIS_INPUT_SIZE;
|
|
54
|
+
canvas.height = IRIS_INPUT_SIZE;
|
|
55
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
56
|
+
if (!ctx)
|
|
57
|
+
throw new Error('irisPrePost: 2d context unavailable');
|
|
58
|
+
cropCtx = ctx;
|
|
59
|
+
}
|
|
60
|
+
return cropCtx;
|
|
61
|
+
}
|
|
62
|
+
/** Draws the eye's ROI from `source` into a 64x64 crop, as [0, 1] RGB. */
|
|
63
|
+
export function preprocessEye(source, roi) {
|
|
64
|
+
const ctx = getCropContext();
|
|
65
|
+
const scale = IRIS_INPUT_SIZE / roi.side;
|
|
66
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
67
|
+
ctx.fillStyle = 'black';
|
|
68
|
+
ctx.fillRect(0, 0, IRIS_INPUT_SIZE, IRIS_INPUT_SIZE);
|
|
69
|
+
ctx.translate(IRIS_INPUT_SIZE / 2, IRIS_INPUT_SIZE / 2);
|
|
70
|
+
if (roi.flip)
|
|
71
|
+
ctx.scale(-1, 1);
|
|
72
|
+
ctx.scale(scale, scale);
|
|
73
|
+
ctx.rotate(-roi.angle);
|
|
74
|
+
ctx.translate(-roi.cx, -roi.cy);
|
|
75
|
+
ctx.drawImage(source, 0, 0);
|
|
76
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
77
|
+
const pixels = ctx.getImageData(0, 0, IRIS_INPUT_SIZE, IRIS_INPUT_SIZE).data;
|
|
78
|
+
const out = new Float32Array(IRIS_INPUT_SIZE * IRIS_INPUT_SIZE * 3);
|
|
79
|
+
for (let i = 0, j = 0; i < pixels.length; i += 4, j += 3) {
|
|
80
|
+
out[j] = pixels[i] / 255;
|
|
81
|
+
out[j + 1] = pixels[i + 1] / 255;
|
|
82
|
+
out[j + 2] = pixels[i + 2] / 255;
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Maps the first `count` contour points from crop pixels back to source-frame
|
|
88
|
+
* pixels: the inverse of preprocessEye's transform.
|
|
89
|
+
*/
|
|
90
|
+
export function projectEyeContour(contour, roi, count) {
|
|
91
|
+
const scale = roi.side / IRIS_INPUT_SIZE;
|
|
92
|
+
const cos = Math.cos(roi.angle);
|
|
93
|
+
const sin = Math.sin(roi.angle);
|
|
94
|
+
const points = new Array(count);
|
|
95
|
+
for (let i = 0; i < count; i++) {
|
|
96
|
+
const u = (contour[i * 3] - IRIS_INPUT_SIZE / 2) * scale * (roi.flip ? -1 : 1);
|
|
97
|
+
const v = (contour[i * 3 + 1] - IRIS_INPUT_SIZE / 2) * scale;
|
|
98
|
+
points[i] = { x: roi.cx + u * cos - v * sin, y: roi.cy + u * sin + v * cos };
|
|
99
|
+
}
|
|
100
|
+
return points;
|
|
101
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Detection } from './blazeFacePrePost';
|
|
2
|
+
export declare const PALM_INPUT_SIZE = 192;
|
|
3
|
+
export declare const PALM_NUM_ANCHORS = 2016;
|
|
4
|
+
export declare const PALM_WRIST = 0;
|
|
5
|
+
export declare const PALM_MIDDLE_MCP = 2;
|
|
6
|
+
/** Frame-pixel box, the shape of `Face.box`. */
|
|
7
|
+
export type Box = {
|
|
8
|
+
xMin: number;
|
|
9
|
+
yMin: number;
|
|
10
|
+
xMax: number;
|
|
11
|
+
yMax: number;
|
|
12
|
+
};
|
|
13
|
+
export type Rect = {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Where a (cropped) source frame lands inside the 192×192 letterboxed input,
|
|
21
|
+
* and the inverse that maps model-space [0, 1] coordinates back to
|
|
22
|
+
* source-frame [0, 1] coordinates: `frame = a + b * model`.
|
|
23
|
+
*/
|
|
24
|
+
export type PalmInputTransform = {
|
|
25
|
+
crop: Rect;
|
|
26
|
+
draw: Rect;
|
|
27
|
+
ax: number;
|
|
28
|
+
bx: number;
|
|
29
|
+
ay: number;
|
|
30
|
+
by: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Letterbox `crop` (frame pixels, default the whole frame, clamped to it) into
|
|
34
|
+
* the model input. Pure so the coordinate round trip is testable without a
|
|
35
|
+
* canvas.
|
|
36
|
+
*/
|
|
37
|
+
export declare function palmInputTransform(frameWidth: number, frameHeight: number, crop?: Box): PalmInputTransform;
|
|
38
|
+
/**
|
|
39
|
+
* Letterbox the frame (or `crop` of it, in frame pixels) into a 192×192 NHWC
|
|
40
|
+
* float32 buffer in [0, 1].
|
|
41
|
+
*/
|
|
42
|
+
export declare function preprocessPalmInput(source: HTMLVideoElement | HTMLCanvasElement, crop?: Box): {
|
|
43
|
+
data: Float32Array;
|
|
44
|
+
transform: PalmInputTransform;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Decode `Identity` [1, 2016, 18] regressors and `Identity_1` [1, 2016, 1]
|
|
48
|
+
* score logits into palms in source-frame [0, 1] coordinates, after MediaPipe's
|
|
49
|
+
* weighted NMS. Keypoint 0 is the wrist, 2 the middle-finger MCP.
|
|
50
|
+
* `scoreThreshold` defaults to MediaPipe's 0.5, which MediaPipe can afford
|
|
51
|
+
* because its hand-landmark stage rejects false palms; alone, faces seen small
|
|
52
|
+
* in the frame score above it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function decodePalms(regressors: Float32Array, classifiers: Float32Array, transform: PalmInputTransform, scoreThreshold?: number): Detection[];
|
|
55
|
+
//# sourceMappingURL=palmPrePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palmPrePost.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/litert/palmPrePost.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,oBAAoB,CAAA;AAEtE,eAAO,MAAM,eAAe,MAAM,CAAA;AAClC,eAAO,MAAM,gBAAgB,OAAO,CAAA;AAOpC,eAAO,MAAM,UAAU,IAAI,CAAA;AAC3B,eAAO,MAAM,eAAe,IAAI,CAAA;AAEhC,gDAAgD;AAChD,MAAM,MAAM,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAC5E,MAAM,MAAM,IAAI,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AA0B1E;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,GAAG,GACT,kBAAkB,CAqBpB;AAgBD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,EAC5C,IAAI,CAAC,EAAE,GAAG,GACT;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,kBAAkB,CAAA;CAAE,CAkBvD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,YAAY,EACxB,WAAW,EAAE,YAAY,EACzB,SAAS,EAAE,kBAAkB,EAC7B,cAAc,SAAkB,GAC/B,SAAS,EAAE,CAqCb"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// MediaPipe palm detection (`palm_detection_lite` / `_full`) pre/post-processing
|
|
2
|
+
// for direct .tflite inference via @litertjs/core.
|
|
3
|
+
//
|
|
4
|
+
// Same SSD family as BlazeFace (see blazeFacePrePost.ts) with the constants
|
|
5
|
+
// from MediaPipe's palm_detection_cpu.pbtxt: 192×192 input, strides
|
|
6
|
+
// [8, 16, 16, 16] → 2 anchors/cell on 24×24 + 6 anchors/cell on 12×12 = 2016
|
|
7
|
+
// anchors, 18 regressors per anchor (4 box + 7 keypoints × 2).
|
|
8
|
+
//
|
|
9
|
+
// Input range is [0, 1], NOT BlazeFace's [-1, 1]. The .tflite carries no
|
|
10
|
+
// normalization metadata; measured 2026-09-13 against MediaPipe's own hand test
|
|
11
|
+
// images, [0, 1] scores 0.95–0.97 on all seven while [-1, 1] misses four of
|
|
12
|
+
// them outright (fist 0.43, both two-hands shots 0.00).
|
|
13
|
+
import { nonMaxSuppression } from './blazeFacePrePost';
|
|
14
|
+
export const PALM_INPUT_SIZE = 192;
|
|
15
|
+
export const PALM_NUM_ANCHORS = 2016;
|
|
16
|
+
const NUM_KEYPOINTS = 7;
|
|
17
|
+
const REGRESSOR_STRIDE = 4 + NUM_KEYPOINTS * 2;
|
|
18
|
+
const SCORE_THRESHOLD = 0.5;
|
|
19
|
+
const IOU_THRESHOLD = 0.3;
|
|
20
|
+
// The keypoint pair MediaPipe orients its hand ROI by.
|
|
21
|
+
export const PALM_WRIST = 0;
|
|
22
|
+
export const PALM_MIDDLE_MCP = 2;
|
|
23
|
+
let cachedAnchors = null;
|
|
24
|
+
function getAnchors() {
|
|
25
|
+
if (cachedAnchors)
|
|
26
|
+
return cachedAnchors;
|
|
27
|
+
const anchors = new Float32Array(PALM_NUM_ANCHORS * 2);
|
|
28
|
+
let i = 0;
|
|
29
|
+
for (const [stride, perCell] of [
|
|
30
|
+
[8, 2],
|
|
31
|
+
[16, 6],
|
|
32
|
+
]) {
|
|
33
|
+
const grid = PALM_INPUT_SIZE / stride;
|
|
34
|
+
for (let y = 0; y < grid; y++) {
|
|
35
|
+
for (let x = 0; x < grid; x++) {
|
|
36
|
+
for (let n = 0; n < perCell; n++) {
|
|
37
|
+
anchors[i++] = (x + 0.5) / grid;
|
|
38
|
+
anchors[i++] = (y + 0.5) / grid;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
cachedAnchors = anchors;
|
|
44
|
+
return anchors;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Letterbox `crop` (frame pixels, default the whole frame, clamped to it) into
|
|
48
|
+
* the model input. Pure so the coordinate round trip is testable without a
|
|
49
|
+
* canvas.
|
|
50
|
+
*/
|
|
51
|
+
export function palmInputTransform(frameWidth, frameHeight, crop) {
|
|
52
|
+
const x = Math.max(0, crop?.xMin ?? 0);
|
|
53
|
+
const y = Math.max(0, crop?.yMin ?? 0);
|
|
54
|
+
const width = Math.min(frameWidth, crop?.xMax ?? frameWidth) - x;
|
|
55
|
+
const height = Math.min(frameHeight, crop?.yMax ?? frameHeight) - y;
|
|
56
|
+
const scale = Math.min(PALM_INPUT_SIZE / width, PALM_INPUT_SIZE / height);
|
|
57
|
+
const drawW = Math.round(width * scale);
|
|
58
|
+
const drawH = Math.round(height * scale);
|
|
59
|
+
const padX = (PALM_INPUT_SIZE - drawW) / 2;
|
|
60
|
+
const padY = (PALM_INPUT_SIZE - drawH) / 2;
|
|
61
|
+
// model → crop: (m * S - pad) / draw * cropSize; crop → frame: (x + ·) / frame.
|
|
62
|
+
const bx = (PALM_INPUT_SIZE * width) / (drawW * frameWidth);
|
|
63
|
+
const by = (PALM_INPUT_SIZE * height) / (drawH * frameHeight);
|
|
64
|
+
return {
|
|
65
|
+
crop: { x, y, width, height },
|
|
66
|
+
draw: { x: padX, y: padY, width: drawW, height: drawH },
|
|
67
|
+
ax: x / frameWidth - (padX / PALM_INPUT_SIZE) * bx,
|
|
68
|
+
bx,
|
|
69
|
+
ay: y / frameHeight - (padY / PALM_INPUT_SIZE) * by,
|
|
70
|
+
by,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
let preprocessCtx = null;
|
|
74
|
+
function getPreprocessContext() {
|
|
75
|
+
if (!preprocessCtx) {
|
|
76
|
+
const canvas = document.createElement('canvas');
|
|
77
|
+
canvas.width = PALM_INPUT_SIZE;
|
|
78
|
+
canvas.height = PALM_INPUT_SIZE;
|
|
79
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
80
|
+
if (!ctx)
|
|
81
|
+
throw new Error('palmPrePost: 2d context unavailable');
|
|
82
|
+
preprocessCtx = ctx;
|
|
83
|
+
}
|
|
84
|
+
return preprocessCtx;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Letterbox the frame (or `crop` of it, in frame pixels) into a 192×192 NHWC
|
|
88
|
+
* float32 buffer in [0, 1].
|
|
89
|
+
*/
|
|
90
|
+
export function preprocessPalmInput(source, crop) {
|
|
91
|
+
const sw = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
|
|
92
|
+
const sh = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
|
|
93
|
+
const transform = palmInputTransform(sw, sh, crop);
|
|
94
|
+
const { crop: c, draw: d } = transform;
|
|
95
|
+
const ctx = getPreprocessContext();
|
|
96
|
+
ctx.fillStyle = 'black';
|
|
97
|
+
ctx.fillRect(0, 0, PALM_INPUT_SIZE, PALM_INPUT_SIZE);
|
|
98
|
+
ctx.drawImage(source, c.x, c.y, c.width, c.height, d.x, d.y, d.width, d.height);
|
|
99
|
+
const pixels = ctx.getImageData(0, 0, PALM_INPUT_SIZE, PALM_INPUT_SIZE).data;
|
|
100
|
+
const data = new Float32Array(PALM_INPUT_SIZE * PALM_INPUT_SIZE * 3);
|
|
101
|
+
for (let i = 0, j = 0; i < pixels.length; i += 4, j += 3) {
|
|
102
|
+
data[j] = pixels[i] / 255;
|
|
103
|
+
data[j + 1] = pixels[i + 1] / 255;
|
|
104
|
+
data[j + 2] = pixels[i + 2] / 255;
|
|
105
|
+
}
|
|
106
|
+
return { data, transform };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Decode `Identity` [1, 2016, 18] regressors and `Identity_1` [1, 2016, 1]
|
|
110
|
+
* score logits into palms in source-frame [0, 1] coordinates, after MediaPipe's
|
|
111
|
+
* weighted NMS. Keypoint 0 is the wrist, 2 the middle-finger MCP.
|
|
112
|
+
* `scoreThreshold` defaults to MediaPipe's 0.5, which MediaPipe can afford
|
|
113
|
+
* because its hand-landmark stage rejects false palms; alone, faces seen small
|
|
114
|
+
* in the frame score above it.
|
|
115
|
+
*/
|
|
116
|
+
export function decodePalms(regressors, classifiers, transform, scoreThreshold = SCORE_THRESHOLD) {
|
|
117
|
+
const anchors = getAnchors();
|
|
118
|
+
const { ax, bx, ay, by } = transform;
|
|
119
|
+
const S = PALM_INPUT_SIZE;
|
|
120
|
+
const detections = [];
|
|
121
|
+
for (let i = 0; i < PALM_NUM_ANCHORS; i++) {
|
|
122
|
+
// Same score clipping as MediaPipe's TfLiteTensorsToDetectionsCalculator.
|
|
123
|
+
const logit = Math.max(-100, Math.min(100, classifiers[i]));
|
|
124
|
+
const score = 1 / (1 + Math.exp(-logit));
|
|
125
|
+
if (score < scoreThreshold)
|
|
126
|
+
continue;
|
|
127
|
+
const anchorX = anchors[i * 2];
|
|
128
|
+
const anchorY = anchors[i * 2 + 1];
|
|
129
|
+
const r = i * REGRESSOR_STRIDE;
|
|
130
|
+
const xc = anchorX + regressors[r] / S;
|
|
131
|
+
const yc = anchorY + regressors[r + 1] / S;
|
|
132
|
+
const w = regressors[r + 2] / S;
|
|
133
|
+
const h = regressors[r + 3] / S;
|
|
134
|
+
const keypoints = [];
|
|
135
|
+
for (let k = 0; k < NUM_KEYPOINTS; k++) {
|
|
136
|
+
keypoints.push({
|
|
137
|
+
x: ax + bx * (anchorX + regressors[r + 4 + k * 2] / S),
|
|
138
|
+
y: ay + by * (anchorY + regressors[r + 5 + k * 2] / S),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
detections.push({
|
|
142
|
+
xMin: ax + bx * (xc - w / 2),
|
|
143
|
+
yMin: ay + by * (yc - h / 2),
|
|
144
|
+
xMax: ax + bx * (xc + w / 2),
|
|
145
|
+
yMax: ay + by * (yc + h / 2),
|
|
146
|
+
keypoints,
|
|
147
|
+
score,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return nonMaxSuppression(detections, IOU_THRESHOLD);
|
|
151
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versions of the packages layered on top of core, supplied by whoever builds
|
|
3
|
+
* the client (e.g. the 2.x façade passes its own and websdk-ui's version).
|
|
4
|
+
*/
|
|
5
|
+
export type SdkLayerVersions = {
|
|
6
|
+
/** The customer-facing SDK version (the 2.x façade's `webSdkVersion`). */
|
|
7
|
+
sdkVersion?: string;
|
|
8
|
+
sdkUiVersion?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Every version reported on the wire, with core's always present. */
|
|
11
|
+
export type ResolvedSdkVersions = {
|
|
12
|
+
/** The customer-facing version; falls back to core's when core is used directly. */
|
|
13
|
+
sdkVersion: string;
|
|
14
|
+
sdkCoreVersion: string;
|
|
15
|
+
sdkUiVersion?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function resolveSdkVersions(layers?: SdkLayerVersions): ResolvedSdkVersions;
|
|
18
|
+
//# sourceMappingURL=sdkVersions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkVersions.d.ts","sourceRoot":"","sources":["../src/sdkVersions.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG;IAChC,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,kBAAkB,CAChC,MAAM,GAAE,gBAAqB,GAC5B,mBAAmB,CAMrB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LightingSample } from './lighting';
|
|
2
|
+
import type { FaceDetectionPrediction } from './faceTracking';
|
|
3
|
+
export type LightingThresholds = {
|
|
4
|
+
minCaptureBrightnessThreshold: number;
|
|
5
|
+
minCaptureRangeThreshold: number;
|
|
6
|
+
minCaptureVarianceThreshold: number;
|
|
7
|
+
};
|
|
8
|
+
/** Opt-in recovery from persistent lighting failures. Framing gates stay on. */
|
|
9
|
+
export type SelfieCaptureRecoveryOptions = {
|
|
10
|
+
/** Offer manual capture after this much active capture time. Default 15000. */
|
|
11
|
+
manualCaptureAfterMs?: number;
|
|
12
|
+
/** When omitted, contrast thresholds do not change. Brightness never decays. */
|
|
13
|
+
lightingRelaxation?: {
|
|
14
|
+
startAfterMs: number;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
rangeFloor: number;
|
|
17
|
+
varianceFloor: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type SelfieCaptureQualityException = {
|
|
21
|
+
reason: 'manual_override' | 'relaxed_thresholds';
|
|
22
|
+
failedChecks: ('brightness' | 'range' | 'variance' | 'unavailable')[];
|
|
23
|
+
measurements: Pick<LightingSample, 'brightness' | 'range' | 'variance'>;
|
|
24
|
+
originalThresholds: LightingThresholds;
|
|
25
|
+
effectiveThresholds: LightingThresholds;
|
|
26
|
+
elapsedMs: number;
|
|
27
|
+
};
|
|
28
|
+
export type SelfieCaptureRecoveryState = {
|
|
29
|
+
elapsedMs: number;
|
|
30
|
+
manualCaptureAvailable: boolean;
|
|
31
|
+
manualCaptureReady: boolean;
|
|
32
|
+
effectiveThresholds: LightingThresholds;
|
|
33
|
+
};
|
|
34
|
+
export declare function resolveLightingThresholds(thresholds: Partial<LightingThresholds>): LightingThresholds;
|
|
35
|
+
/** Reject invalid policies rather than silently disabling a capture barrier. */
|
|
36
|
+
export declare function validateCaptureRecovery(options: SelfieCaptureRecoveryOptions): void;
|
|
37
|
+
/** Linear, bounded contrast relaxation; a floor above the baseline cannot tighten it. */
|
|
38
|
+
export declare function captureRecoveryState(options: SelfieCaptureRecoveryOptions, original: LightingThresholds, elapsedMs: number): SelfieCaptureRecoveryState;
|
|
39
|
+
/** Manual recovery bypasses lighting only; the subject must still be ready. */
|
|
40
|
+
export declare function faceReadyWithoutLighting(prediction: FaceDetectionPrediction | null): boolean;
|
|
41
|
+
/** Records what the original policy would have rejected on the committed frame. */
|
|
42
|
+
export declare function captureQualityException(reason: SelfieCaptureQualityException['reason'], measurements: SelfieCaptureQualityException['measurements'], originalThresholds: LightingThresholds, recovery: SelfieCaptureRecoveryState): SelfieCaptureQualityException | undefined;
|
|
43
|
+
//# sourceMappingURL=captureQuality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureQuality.d.ts","sourceRoot":"","sources":["../../src/selfieCapture/captureQuality.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAE7D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6BAA6B,EAAE,MAAM,CAAA;IACrC,wBAAwB,EAAE,MAAM,CAAA;IAChC,2BAA2B,EAAE,MAAM,CAAA;CACpC,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,4BAA4B,GAAG;IACzC,+EAA+E;IAC/E,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,gFAAgF;IAChF,kBAAkB,CAAC,EAAE;QACnB,YAAY,EAAE,MAAM,CAAA;QACpB,UAAU,EAAE,MAAM,CAAA;QAClB,UAAU,EAAE,MAAM,CAAA;QAClB,aAAa,EAAE,MAAM,CAAA;KACtB,CAAA;CACF,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,CAAA;IAChD,YAAY,EAAE,CAAC,YAAY,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,CAAC,EAAE,CAAA;IACrE,YAAY,EAAE,IAAI,CAAC,cAAc,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,CAAA;IACvE,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,mBAAmB,EAAE,kBAAkB,CAAA;IACvC,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,MAAM,CAAA;IACjB,sBAAsB,EAAE,OAAO,CAAA;IAC/B,kBAAkB,EAAE,OAAO,CAAA;IAC3B,mBAAmB,EAAE,kBAAkB,CAAA;CACxC,CAAA;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACtC,kBAAkB,CAYpB;AAED,gFAAgF;AAChF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,4BAA4B,GACpC,IAAI,CAmBN;AAED,yFAAyF;AACzF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,4BAA4B,EACrC,QAAQ,EAAE,kBAAkB,EAC5B,SAAS,EAAE,MAAM,GAChB,0BAA0B,CA4B5B;AAED,+EAA+E;AAC/E,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,uBAAuB,GAAG,IAAI,GACzC,OAAO,CAaT;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,6BAA6B,CAAC,QAAQ,CAAC,EAC/C,YAAY,EAAE,6BAA6B,CAAC,cAAc,CAAC,EAC3D,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,0BAA0B,GACnC,6BAA6B,GAAG,SAAS,CAsB3C"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DEFAULT_MIN_CAPTURE_BRIGHTNESS_THRESHOLD, DEFAULT_MIN_CAPTURE_RANGE_THRESHOLD, DEFAULT_MIN_CAPTURE_VARIANCE_THRESHOLD, } from './lighting';
|
|
2
|
+
export function resolveLightingThresholds(thresholds) {
|
|
3
|
+
return {
|
|
4
|
+
minCaptureBrightnessThreshold: thresholds.minCaptureBrightnessThreshold ??
|
|
5
|
+
DEFAULT_MIN_CAPTURE_BRIGHTNESS_THRESHOLD,
|
|
6
|
+
minCaptureRangeThreshold: thresholds.minCaptureRangeThreshold ??
|
|
7
|
+
DEFAULT_MIN_CAPTURE_RANGE_THRESHOLD,
|
|
8
|
+
minCaptureVarianceThreshold: thresholds.minCaptureVarianceThreshold ??
|
|
9
|
+
DEFAULT_MIN_CAPTURE_VARIANCE_THRESHOLD,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** Reject invalid policies rather than silently disabling a capture barrier. */
|
|
13
|
+
export function validateCaptureRecovery(options) {
|
|
14
|
+
const values = [options.manualCaptureAfterMs ?? 15000];
|
|
15
|
+
const relaxation = options.lightingRelaxation;
|
|
16
|
+
if (relaxation) {
|
|
17
|
+
values.push(relaxation.startAfterMs, relaxation.durationMs, relaxation.rangeFloor, relaxation.varianceFloor);
|
|
18
|
+
}
|
|
19
|
+
if (values.some((value) => !Number.isFinite(value) || value < 0)) {
|
|
20
|
+
throw new Error('Capture recovery durations and contrast floors must be finite and nonnegative.');
|
|
21
|
+
}
|
|
22
|
+
if (options.lightingRelaxation?.durationMs === 0) {
|
|
23
|
+
throw new Error('Lighting relaxation duration must be greater than zero.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Linear, bounded contrast relaxation; a floor above the baseline cannot tighten it. */
|
|
27
|
+
export function captureRecoveryState(options, original, elapsedMs) {
|
|
28
|
+
const relaxation = options.lightingRelaxation;
|
|
29
|
+
const progress = relaxation
|
|
30
|
+
? Math.max(0, Math.min(1, (elapsedMs - relaxation.startAfterMs) / relaxation.durationMs))
|
|
31
|
+
: 0;
|
|
32
|
+
const relax = (threshold, floor) => threshold - (threshold - Math.min(threshold, floor)) * progress;
|
|
33
|
+
return {
|
|
34
|
+
elapsedMs,
|
|
35
|
+
manualCaptureAvailable: elapsedMs >= (options.manualCaptureAfterMs ?? 15000),
|
|
36
|
+
manualCaptureReady: false,
|
|
37
|
+
effectiveThresholds: {
|
|
38
|
+
...original,
|
|
39
|
+
minCaptureRangeThreshold: relaxation
|
|
40
|
+
? relax(original.minCaptureRangeThreshold, relaxation.rangeFloor)
|
|
41
|
+
: original.minCaptureRangeThreshold,
|
|
42
|
+
minCaptureVarianceThreshold: relaxation
|
|
43
|
+
? relax(original.minCaptureVarianceThreshold, relaxation.varianceFloor)
|
|
44
|
+
: original.minCaptureVarianceThreshold,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Manual recovery bypasses lighting only; the subject must still be ready. */
|
|
49
|
+
export function faceReadyWithoutLighting(prediction) {
|
|
50
|
+
return Boolean(prediction?.face &&
|
|
51
|
+
!prediction.faceNotDetected &&
|
|
52
|
+
!prediction.faceNotCentered &&
|
|
53
|
+
!prediction.faceLookingAway &&
|
|
54
|
+
!prediction.faceTooClose &&
|
|
55
|
+
!prediction.faceTooFar &&
|
|
56
|
+
prediction.faceIsStable &&
|
|
57
|
+
prediction.noseIsStable &&
|
|
58
|
+
!prediction.eyesClosed &&
|
|
59
|
+
!prediction.eyesCalibrating);
|
|
60
|
+
}
|
|
61
|
+
/** Records what the original policy would have rejected on the committed frame. */
|
|
62
|
+
export function captureQualityException(reason, measurements, originalThresholds, recovery) {
|
|
63
|
+
const failedChecks = [];
|
|
64
|
+
for (const [check, threshold] of [
|
|
65
|
+
['brightness', originalThresholds.minCaptureBrightnessThreshold],
|
|
66
|
+
['range', originalThresholds.minCaptureRangeThreshold],
|
|
67
|
+
['variance', originalThresholds.minCaptureVarianceThreshold],
|
|
68
|
+
]) {
|
|
69
|
+
const value = measurements[check];
|
|
70
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
71
|
+
if (!failedChecks.includes('unavailable'))
|
|
72
|
+
failedChecks.push('unavailable');
|
|
73
|
+
}
|
|
74
|
+
else if (value < threshold)
|
|
75
|
+
failedChecks.push(check);
|
|
76
|
+
}
|
|
77
|
+
if (failedChecks.length === 0)
|
|
78
|
+
return undefined;
|
|
79
|
+
return {
|
|
80
|
+
reason,
|
|
81
|
+
failedChecks,
|
|
82
|
+
measurements,
|
|
83
|
+
originalThresholds,
|
|
84
|
+
effectiveThresholds: recovery.effectiveThresholds,
|
|
85
|
+
elapsedMs: recovery.elapsedMs,
|
|
86
|
+
};
|
|
87
|
+
}
|