@idmission/websdk-core 0.1.0-rc.1
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 +66 -0
- package/dist/attestation/attestationState.d.ts +24 -0
- package/dist/attestation/attestationState.d.ts.map +1 -0
- package/dist/attestation/attestationState.js +57 -0
- package/dist/attestation/clientAttestation.d.ts +40 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -0
- package/dist/attestation/clientAttestation.js +19 -0
- package/dist/attestation/collectClientAttestation.d.ts +10 -0
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -0
- package/dist/attestation/collectClientAttestation.js +18 -0
- package/dist/attestation/index.d.ts +5 -0
- package/dist/attestation/index.d.ts.map +1 -0
- package/dist/attestation/index.js +4 -0
- package/dist/attestation/nativeAttestationBridge.d.ts +3 -0
- package/dist/attestation/nativeAttestationBridge.d.ts.map +1 -0
- package/dist/attestation/nativeAttestationBridge.js +38 -0
- package/dist/barcode/AAMVAParser.d.ts +77 -0
- package/dist/barcode/AAMVAParser.d.ts.map +1 -0
- package/dist/barcode/AAMVAParser.js +422 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts +157 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts.map +1 -0
- package/dist/barcode/NativeBarcodeDecoder.js +832 -0
- package/dist/barcode/Parse.d.ts +6 -0
- package/dist/barcode/Parse.d.ts.map +1 -0
- package/dist/barcode/Parse.js +148 -0
- package/dist/barcode/decodeSummary.d.ts +45 -0
- package/dist/barcode/decodeSummary.d.ts.map +1 -0
- package/dist/barcode/decodeSummary.js +23 -0
- package/dist/barcode/index.d.ts +5 -0
- package/dist/barcode/index.d.ts.map +1 -0
- package/dist/barcode/index.js +4 -0
- package/dist/camera/Camera.d.ts +37 -0
- package/dist/camera/Camera.d.ts.map +1 -0
- package/dist/camera/Camera.js +453 -0
- package/dist/camera/acquireCamera.d.ts +29 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -0
- package/dist/camera/acquireCamera.js +224 -0
- package/dist/camera/cameraSignals.d.ts +23 -0
- package/dist/camera/cameraSignals.d.ts.map +1 -0
- package/dist/camera/cameraSignals.js +32 -0
- package/dist/camera/getUserMediaIntegrity.d.ts +72 -0
- package/dist/camera/getUserMediaIntegrity.d.ts.map +1 -0
- package/dist/camera/getUserMediaIntegrity.js +256 -0
- package/dist/camera/index.d.ts +6 -0
- package/dist/camera/index.d.ts.map +1 -0
- package/dist/camera/index.js +5 -0
- package/dist/camera/isVirtualCamera.d.ts +10 -0
- package/dist/camera/isVirtualCamera.d.ts.map +1 -0
- package/dist/camera/isVirtualCamera.js +11 -0
- package/dist/client/IdmissionClient.d.ts +151 -0
- package/dist/client/IdmissionClient.d.ts.map +1 -0
- package/dist/client/IdmissionClient.js +638 -0
- package/dist/client/additionalDocument.d.ts +14 -0
- package/dist/client/additionalDocument.d.ts.map +1 -0
- package/dist/client/additionalDocument.js +24 -0
- package/dist/client/artifacts.d.ts +146 -0
- package/dist/client/artifacts.d.ts.map +1 -0
- package/dist/client/artifacts.js +1 -0
- package/dist/client/blobToB64.d.ts +2 -0
- package/dist/client/blobToB64.d.ts.map +1 -0
- package/dist/client/blobToB64.js +17 -0
- package/dist/client/endpoints.d.ts +7 -0
- package/dist/client/endpoints.d.ts.map +1 -0
- package/dist/client/endpoints.js +59 -0
- package/dist/client/errors.d.ts +20 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +45 -0
- package/dist/client/index.d.ts +23 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +38 -0
- package/dist/client/payload.d.ts +36 -0
- package/dist/client/payload.d.ts.map +1 -0
- package/dist/client/payload.js +397 -0
- package/dist/client/sessionMachine.d.ts +26 -0
- package/dist/client/sessionMachine.d.ts.map +1 -0
- package/dist/client/sessionMachine.js +23 -0
- package/dist/client/submissionMetadata.d.ts +31 -0
- package/dist/client/submissionMetadata.d.ts.map +1 -0
- package/dist/client/submissionMetadata.js +90 -0
- package/dist/client/timings.d.ts +49 -0
- package/dist/client/timings.d.ts.map +1 -0
- package/dist/client/timings.js +32 -0
- package/dist/client/types.d.ts +305 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +18 -0
- package/dist/client/upload.d.ts +60 -0
- package/dist/client/upload.d.ts.map +1 -0
- package/dist/client/upload.js +313 -0
- package/dist/client/uploadedDocument.d.ts +7 -0
- package/dist/client/uploadedDocument.d.ts.map +1 -0
- package/dist/client/uploadedDocument.js +4 -0
- package/dist/client/urls.d.ts +30 -0
- package/dist/client/urls.d.ts.map +1 -0
- package/dist/client/urls.js +73 -0
- package/dist/client/validateSession.d.ts +7 -0
- package/dist/client/validateSession.d.ts.map +1 -0
- package/dist/client/validateSession.js +63 -0
- package/dist/config/cdn.d.ts +2 -0
- package/dist/config/cdn.d.ts.map +1 -0
- package/dist/config/cdn.js +1 -0
- package/dist/diagnostics/buffer.d.ts +8 -0
- package/dist/diagnostics/buffer.d.ts.map +1 -0
- package/dist/diagnostics/buffer.js +25 -0
- package/dist/diagnostics/envCapability.d.ts +3 -0
- package/dist/diagnostics/envCapability.d.ts.map +1 -0
- package/dist/diagnostics/envCapability.js +40 -0
- package/dist/diagnostics/floodControl.d.ts +6 -0
- package/dist/diagnostics/floodControl.d.ts.map +1 -0
- package/dist/diagnostics/floodControl.js +29 -0
- package/dist/diagnostics/index.d.ts +8 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +17 -0
- package/dist/diagnostics/install.d.ts +20 -0
- package/dist/diagnostics/install.d.ts.map +1 -0
- package/dist/diagnostics/install.js +159 -0
- package/dist/diagnostics/redaction.d.ts +7 -0
- package/dist/diagnostics/redaction.d.ts.map +1 -0
- package/dist/diagnostics/redaction.js +73 -0
- package/dist/diagnostics/transport.d.ts +15 -0
- package/dist/diagnostics/transport.d.ts.map +1 -0
- package/dist/diagnostics/transport.js +35 -0
- package/dist/diagnostics/types.d.ts +59 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +1 -0
- package/dist/documentCapture/controller.d.ts +35 -0
- package/dist/documentCapture/controller.d.ts.map +1 -0
- package/dist/documentCapture/controller.js +254 -0
- package/dist/documentCapture/index.d.ts +4 -0
- package/dist/documentCapture/index.d.ts.map +1 -0
- package/dist/documentCapture/index.js +8 -0
- package/dist/documentCapture/reducer.d.ts +31 -0
- package/dist/documentCapture/reducer.d.ts.map +1 -0
- package/dist/documentCapture/reducer.js +87 -0
- package/dist/documentCapture/state.d.ts +49 -0
- package/dist/documentCapture/state.d.ts.map +1 -0
- package/dist/documentCapture/state.js +36 -0
- package/dist/idCapture/controller.d.ts +228 -0
- package/dist/idCapture/controller.d.ts.map +1 -0
- package/dist/idCapture/controller.js +1453 -0
- package/dist/idCapture/errors.d.ts +36 -0
- package/dist/idCapture/errors.d.ts.map +1 -0
- package/dist/idCapture/errors.js +18 -0
- package/dist/idCapture/guidance.d.ts +80 -0
- package/dist/idCapture/guidance.d.ts.map +1 -0
- package/dist/idCapture/guidance.js +143 -0
- package/dist/idCapture/index.d.ts +22 -0
- package/dist/idCapture/index.d.ts.map +1 -0
- package/dist/idCapture/index.js +46 -0
- package/dist/idCapture/phase.d.ts +10 -0
- package/dist/idCapture/phase.d.ts.map +1 -0
- package/dist/idCapture/phase.js +28 -0
- package/dist/idCapture/pipeline.d.ts +176 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -0
- package/dist/idCapture/pipeline.js +1028 -0
- package/dist/idCapture/reducer.d.ts +3 -0
- package/dist/idCapture/reducer.d.ts.map +1 -0
- package/dist/idCapture/reducer.js +661 -0
- package/dist/idCapture/requirements.d.ts +10 -0
- package/dist/idCapture/requirements.d.ts.map +1 -0
- package/dist/idCapture/requirements.js +43 -0
- package/dist/idCapture/stabilizer.d.ts +2 -0
- package/dist/idCapture/stabilizer.d.ts.map +1 -0
- package/dist/idCapture/stabilizer.js +4 -0
- package/dist/idCapture/state.d.ts +426 -0
- package/dist/idCapture/state.d.ts.map +1 -0
- package/dist/idCapture/state.js +91 -0
- package/dist/idCapture/submit.d.ts +33 -0
- package/dist/idCapture/submit.d.ts.map +1 -0
- package/dist/idCapture/submit.js +105 -0
- package/dist/idCapture/types.d.ts +20 -0
- package/dist/idCapture/types.d.ts.map +1 -0
- package/dist/idCapture/types.js +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/liveness/challengeGeometry.d.ts +66 -0
- package/dist/liveness/challengeGeometry.d.ts.map +1 -0
- package/dist/liveness/challengeGeometry.js +226 -0
- package/dist/liveness/challengeSequence.d.ts +49 -0
- package/dist/liveness/challengeSequence.d.ts.map +1 -0
- package/dist/liveness/challengeSequence.js +71 -0
- package/dist/liveness/index.d.ts +4 -0
- package/dist/liveness/index.d.ts.map +1 -0
- package/dist/liveness/index.js +3 -0
- package/dist/liveness/livenessResult.d.ts +11 -0
- package/dist/liveness/livenessResult.d.ts.map +1 -0
- package/dist/liveness/livenessResult.js +16 -0
- package/dist/models/BarcodeReadability.d.ts +36 -0
- package/dist/models/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/BarcodeReadability.js +71 -0
- package/dist/models/CapabilityProbing.d.ts +25 -0
- package/dist/models/CapabilityProbing.d.ts.map +1 -0
- package/dist/models/CapabilityProbing.js +172 -0
- package/dist/models/DocumentDetection.d.ts +96 -0
- package/dist/models/DocumentDetection.d.ts.map +1 -0
- package/dist/models/DocumentDetection.js +257 -0
- package/dist/models/FaceDetection.d.ts +21 -0
- package/dist/models/FaceDetection.d.ts.map +1 -0
- package/dist/models/FaceDetection.js +4 -0
- package/dist/models/Focus.d.ts +36 -0
- package/dist/models/Focus.d.ts.map +1 -0
- package/dist/models/Focus.js +69 -0
- package/dist/models/FrameLoop.d.ts +13 -0
- package/dist/models/FrameLoop.d.ts.map +1 -0
- package/dist/models/FrameLoop.js +56 -0
- package/dist/models/VisionRuntime.d.ts +18 -0
- package/dist/models/VisionRuntime.d.ts.map +1 -0
- package/dist/models/VisionRuntime.js +158 -0
- package/dist/models/defaults/BarcodeReadability.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadability.js +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.js +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetector.js +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.js +3 -0
- package/dist/models/defaults/FaceDetector.d.ts +3 -0
- package/dist/models/defaults/FaceDetector.d.ts.map +1 -0
- package/dist/models/defaults/FaceDetector.js +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarker.js +8 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.js +3 -0
- package/dist/models/defaults/Focus.d.ts +3 -0
- package/dist/models/defaults/Focus.d.ts.map +1 -0
- package/dist/models/defaults/Focus.js +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FocusLiteRT.js +3 -0
- package/dist/models/defaults/index.d.ts +31 -0
- package/dist/models/defaults/index.d.ts.map +1 -0
- package/dist/models/defaults/index.js +38 -0
- package/dist/models/helpers.d.ts +25 -0
- package/dist/models/helpers.d.ts.map +1 -0
- package/dist/models/helpers.js +98 -0
- package/dist/models/index.d.ts +15 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +14 -0
- package/dist/models/modelLifecycle.d.ts +26 -0
- package/dist/models/modelLifecycle.d.ts.map +1 -0
- package/dist/models/modelLifecycle.js +137 -0
- package/dist/models/occlusion.d.ts +20 -0
- package/dist/models/occlusion.d.ts.map +1 -0
- package/dist/models/occlusion.js +109 -0
- package/dist/models/passportBooklet.d.ts +34 -0
- package/dist/models/passportBooklet.d.ts.map +1 -0
- package/dist/models/passportBooklet.js +152 -0
- package/dist/models/preloadModels.d.ts +42 -0
- package/dist/models/preloadModels.d.ts.map +1 -0
- package/dist/models/preloadModels.js +204 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/litert/BarcodeReadability.js +135 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts +3 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/litert/CapabilityProbe.js +44 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts +18 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/DocumentDetection.js +194 -0
- package/dist/models/providers/litert/FaceDetection.d.ts +11 -0
- package/dist/models/providers/litert/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceDetection.js +204 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts +11 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceLandmarker.js +199 -0
- package/dist/models/providers/litert/Focus.d.ts +11 -0
- package/dist/models/providers/litert/Focus.d.ts.map +1 -0
- package/dist/models/providers/litert/Focus.js +141 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts +6 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.js +68 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts +30 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +206 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts +25 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/docDetectPrePost.js +197 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts +23 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/faceMeshPrePost.js +86 -0
- package/dist/models/providers/litert/focusPrePost.d.ts +6 -0
- package/dist/models/providers/litert/focusPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/focusPrePost.js +67 -0
- package/dist/models/providers/litert/runtime.d.ts +14 -0
- package/dist/models/providers/litert/runtime.d.ts.map +1 -0
- package/dist/models/providers/litert/runtime.js +83 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.js +68 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts +2 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.js +14 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts +12 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/DocumentDetection.js +90 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts +11 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceDetection.js +93 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts +46 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.js +166 -0
- package/dist/models/providers/mediapipe/Focus.d.ts +11 -0
- package/dist/models/providers/mediapipe/Focus.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/Focus.js +51 -0
- package/dist/models/runtimeSelection.d.ts +5 -0
- package/dist/models/runtimeSelection.d.ts.map +1 -0
- package/dist/models/runtimeSelection.js +21 -0
- package/dist/selfieCapture/challengeRunner.d.ts +38 -0
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -0
- package/dist/selfieCapture/challengeRunner.js +181 -0
- package/dist/selfieCapture/controller.d.ts +166 -0
- package/dist/selfieCapture/controller.d.ts.map +1 -0
- package/dist/selfieCapture/controller.js +1253 -0
- package/dist/selfieCapture/faceTracking.d.ts +67 -0
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -0
- package/dist/selfieCapture/faceTracking.js +158 -0
- package/dist/selfieCapture/guidance.d.ts +24 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -0
- package/dist/selfieCapture/guidance.js +41 -0
- package/dist/selfieCapture/index.d.ts +18 -0
- package/dist/selfieCapture/index.d.ts.map +1 -0
- package/dist/selfieCapture/index.js +11 -0
- package/dist/selfieCapture/lighting.d.ts +36 -0
- package/dist/selfieCapture/lighting.d.ts.map +1 -0
- package/dist/selfieCapture/lighting.js +95 -0
- package/dist/selfieCapture/livenessMachine.d.ts +66 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -0
- package/dist/selfieCapture/livenessMachine.js +137 -0
- package/dist/selfieCapture/pipeline.d.ts +42 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -0
- package/dist/selfieCapture/pipeline.js +282 -0
- package/dist/selfieCapture/reducer.d.ts +35 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -0
- package/dist/selfieCapture/reducer.js +143 -0
- package/dist/selfieCapture/state.d.ts +40 -0
- package/dist/selfieCapture/state.d.ts.map +1 -0
- package/dist/selfieCapture/state.js +36 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts +43 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts.map +1 -0
- package/dist/selfieCapture/testing/challengeFixtures.js +43 -0
- package/dist/signature/frameDecode.d.ts +48 -0
- package/dist/signature/frameDecode.d.ts.map +1 -0
- package/dist/signature/frameDecode.js +491 -0
- package/dist/signature/index.d.ts +5 -0
- package/dist/signature/index.d.ts.map +1 -0
- package/dist/signature/index.js +4 -0
- package/dist/signature/metadata.d.ts +63 -0
- package/dist/signature/metadata.d.ts.map +1 -0
- package/dist/signature/metadata.js +1 -0
- package/dist/signature/quality.d.ts +169 -0
- package/dist/signature/quality.d.ts.map +1 -0
- package/dist/signature/quality.js +186 -0
- package/dist/signature/signatureValidity.d.ts +149 -0
- package/dist/signature/signatureValidity.d.ts.map +1 -0
- package/dist/signature/signatureValidity.js +305 -0
- package/dist/signatureCapture/controller.d.ts +67 -0
- package/dist/signatureCapture/controller.d.ts.map +1 -0
- package/dist/signatureCapture/controller.js +534 -0
- package/dist/signatureCapture/guidance.d.ts +9 -0
- package/dist/signatureCapture/guidance.d.ts.map +1 -0
- package/dist/signatureCapture/guidance.js +7 -0
- package/dist/signatureCapture/index.d.ts +6 -0
- package/dist/signatureCapture/index.d.ts.map +1 -0
- package/dist/signatureCapture/index.js +5 -0
- package/dist/signatureCapture/pipeline.d.ts +111 -0
- package/dist/signatureCapture/pipeline.d.ts.map +1 -0
- package/dist/signatureCapture/pipeline.js +680 -0
- package/dist/signatureCapture/reducer.d.ts +42 -0
- package/dist/signatureCapture/reducer.d.ts.map +1 -0
- package/dist/signatureCapture/reducer.js +159 -0
- package/dist/signatureCapture/state.d.ts +92 -0
- package/dist/signatureCapture/state.d.ts.map +1 -0
- package/dist/signatureCapture/state.js +24 -0
- package/dist/utils/canvas.d.ts +4 -0
- package/dist/utils/canvas.d.ts.map +1 -0
- package/dist/utils/canvas.js +21 -0
- package/dist/utils/cropping.d.ts +8 -0
- package/dist/utils/cropping.d.ts.map +1 -0
- package/dist/utils/cropping.js +85 -0
- package/dist/utils/dataUrlToBase64.d.ts +7 -0
- package/dist/utils/dataUrlToBase64.d.ts.map +1 -0
- package/dist/utils/dataUrlToBase64.js +67 -0
- package/dist/utils/getFrameDimensions.d.ts +3 -0
- package/dist/utils/getFrameDimensions.d.ts.map +1 -0
- package/dist/utils/getFrameDimensions.js +12 -0
- package/dist/utils/isMobile.d.ts +3 -0
- package/dist/utils/isMobile.d.ts.map +1 -0
- package/dist/utils/isMobile.js +36 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +25 -0
- package/dist/utils/platform.d.ts +4 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +11 -0
- package/dist/utils/stabilizer.d.ts +26 -0
- package/dist/utils/stabilizer.d.ts.map +1 -0
- package/dist/utils/stabilizer.js +65 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/dist/videoIdCapture/controller.d.ts +108 -0
- package/dist/videoIdCapture/controller.d.ts.map +1 -0
- package/dist/videoIdCapture/controller.js +833 -0
- package/dist/videoIdCapture/index.d.ts +5 -0
- package/dist/videoIdCapture/index.d.ts.map +1 -0
- package/dist/videoIdCapture/index.js +2 -0
- package/dist/videoIdCapture/state.d.ts +88 -0
- package/dist/videoIdCapture/state.d.ts.map +1 -0
- package/dist/videoIdCapture/state.js +67 -0
- package/package.json +111 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const DOC_DETECT_INPUT_SIZE = 300;
|
|
2
|
+
export declare const DOC_DETECT_LABEL_MAP: Record<number, string>;
|
|
3
|
+
export declare const DEFAULT_SCALE_FACTORS: readonly [number, number, number, number];
|
|
4
|
+
export type DocDetection = {
|
|
5
|
+
classId: number;
|
|
6
|
+
label: string;
|
|
7
|
+
score: number;
|
|
8
|
+
xMin: number;
|
|
9
|
+
yMin: number;
|
|
10
|
+
xMax: number;
|
|
11
|
+
yMax: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function preprocessFrame(source: HTMLVideoElement | HTMLCanvasElement): Uint8Array<ArrayBuffer>;
|
|
14
|
+
export type RawOutputs = {
|
|
15
|
+
boxEncodings: Float32Array;
|
|
16
|
+
classPredictions: Float32Array;
|
|
17
|
+
anchors: Float32Array;
|
|
18
|
+
};
|
|
19
|
+
export type RawDecodeOptions = {
|
|
20
|
+
scoreThreshold?: number;
|
|
21
|
+
iouThreshold?: number;
|
|
22
|
+
scaleFactors?: readonly [number, number, number, number];
|
|
23
|
+
};
|
|
24
|
+
export declare function decodeRawDetections(outputs: RawOutputs, options: RawDecodeOptions): DocDetection[];
|
|
25
|
+
//# sourceMappingURL=docDetectPrePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docDetectPrePost.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/litert/docDetectPrePost.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAYzC,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA0BvD,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CACpD,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IAGd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAyBF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,GAC3C,UAAU,CAAC,WAAW,CAAC,CAgBzB;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,YAAY,CAAC;IAC/B,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1D,CAAC;AA4BF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,gBAAgB,GACxB,YAAY,EAAE,CA2FhB"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Pre/post-processing for the DocumentDetector .tflite — raw SSD outputs
|
|
2
|
+
// (post-stripping of the embedded `TFLite_Detection_PostProcess` head).
|
|
3
|
+
//
|
|
4
|
+
// Input contract:
|
|
5
|
+
// `input` — uint8 [1, 300, 300, 3], stretch-resized RGB. The model is
|
|
6
|
+
// quantized for `(px - 127.5) / 127.5` input normalization with
|
|
7
|
+
// scale ≈ 2/255 and zero_point ≈ 128, which means raw 0-255 pixel bytes
|
|
8
|
+
// are a close enough quantized representation that the model produces
|
|
9
|
+
// sensible outputs without explicit dequant/requant on the input.
|
|
10
|
+
//
|
|
11
|
+
// Output contract (three float32 tensors). The 20260602 re-export renamed the
|
|
12
|
+
// outputs to generic `StatefulPartitionedCall:N` (LiteRT.js surfaces these as
|
|
13
|
+
// `output_N`) and reordered them, so the loader identifies them by shape+dtype,
|
|
14
|
+
// not name (see providers/litert/DocumentDetection.ts):
|
|
15
|
+
// box encodings — float32 [1, 1917, 4] (ty, tx, th, tw) deltas
|
|
16
|
+
// class predictions — float32 [1, 1917, 23] per-anchor scores (class 0 = background)
|
|
17
|
+
// anchors — float32 [1917, 4] (ycenter, xcenter, h, w) priors
|
|
18
|
+
//
|
|
19
|
+
// This export is NOT quantized — outputs are float32 and consumed directly,
|
|
20
|
+
// with no dequantization step. The class output has sigmoid applied *inside*
|
|
21
|
+
// the model graph, so values are scores in [0, 1] directly — do NOT re-apply
|
|
22
|
+
// sigmoid client-side. (The earlier export was uint8-quantized and required
|
|
23
|
+
// per-tensor scale/zero_point that LiteRT.js doesn't surface; the float export
|
|
24
|
+
// removes that fragility.)
|
|
25
|
+
//
|
|
26
|
+
// Decode uses the standard TF Object Detection API SSD formula:
|
|
27
|
+
// w = exp(tw / w_scale) * wa
|
|
28
|
+
// h = exp(th / h_scale) * ha
|
|
29
|
+
// ycenter = ty / y_scale * ha + ycenter_a
|
|
30
|
+
// xcenter = tx / x_scale * wa + xcenter_a
|
|
31
|
+
// with scale factors (10, 10, 5, 5). Per-class NMS is applied client-side.
|
|
32
|
+
export const DOC_DETECT_INPUT_SIZE = 300;
|
|
33
|
+
// Class index → human-readable label, per the ML team's `label_map`. This map
|
|
34
|
+
// is LiteRT-model-specific — the MediaPipe detector carries its own labels
|
|
35
|
+
// embedded in its .tflite. The two are kept separate on purpose: the models
|
|
36
|
+
// number their classes differently, so the only safe interop surface is the
|
|
37
|
+
// resulting label *string* (matched in the shared DocumentDetection.ts).
|
|
38
|
+
// The raw model emits class indices 0..22 where 0 is background; the
|
|
39
|
+
// remaining 1..22 map directly to these labels (no further offset needed —
|
|
40
|
+
// the team's "+1" instruction applies to a different indexing convention
|
|
41
|
+
// that we don't use here, since our loop already skips background and
|
|
42
|
+
// preserves the model's 1-based class index).
|
|
43
|
+
export const DOC_DETECT_LABEL_MAP = {
|
|
44
|
+
1: "Document",
|
|
45
|
+
2: "MRZ",
|
|
46
|
+
3: "PDF417",
|
|
47
|
+
4: "Primary face",
|
|
48
|
+
5: "Secondary face",
|
|
49
|
+
6: "Glare",
|
|
50
|
+
7: "Punch Hole",
|
|
51
|
+
8: "Passport page",
|
|
52
|
+
9: "Hologram",
|
|
53
|
+
10: "Primary signature",
|
|
54
|
+
11: "Official signature",
|
|
55
|
+
12: "1-D barcode",
|
|
56
|
+
13: "QR code",
|
|
57
|
+
14: "Fingerprint",
|
|
58
|
+
15: "Finger",
|
|
59
|
+
16: "Real ID star",
|
|
60
|
+
17: "Watermark",
|
|
61
|
+
18: "NFC chip",
|
|
62
|
+
19: "Issuer emblem",
|
|
63
|
+
20: "Document back",
|
|
64
|
+
21: "Document title",
|
|
65
|
+
// "Single page" resolves to detectedDocumentType="singlePage" in the shared
|
|
66
|
+
// post-processor (DocumentDetection.ts). The string must match the MediaPipe
|
|
67
|
+
// model's label for the same concept so both runtimes route identically.
|
|
68
|
+
22: "Single page",
|
|
69
|
+
};
|
|
70
|
+
export const DEFAULT_SCALE_FACTORS = [10.0, 10.0, 5.0, 5.0];
|
|
71
|
+
let preprocessCanvas = null;
|
|
72
|
+
let preprocessCtx = null;
|
|
73
|
+
function getPreprocessContext() {
|
|
74
|
+
if (!preprocessCtx) {
|
|
75
|
+
preprocessCanvas = document.createElement("canvas");
|
|
76
|
+
preprocessCanvas.width = DOC_DETECT_INPUT_SIZE;
|
|
77
|
+
preprocessCanvas.height = DOC_DETECT_INPUT_SIZE;
|
|
78
|
+
const ctx = preprocessCanvas.getContext("2d", { willReadFrequently: true });
|
|
79
|
+
if (!ctx)
|
|
80
|
+
throw new Error("docDetectPrePost: 2d context unavailable");
|
|
81
|
+
preprocessCtx = ctx;
|
|
82
|
+
}
|
|
83
|
+
return preprocessCtx;
|
|
84
|
+
}
|
|
85
|
+
// Stretch-resize into 300×300 NHWC uint8. The reference Python script uses
|
|
86
|
+
// a direct cv2.resize with no letterboxing.
|
|
87
|
+
//
|
|
88
|
+
// Return type narrows to `Uint8Array<ArrayBuffer>` (not the default
|
|
89
|
+
// `Uint8Array<ArrayBufferLike>`) because we always allocate a fresh
|
|
90
|
+
// `new Uint8Array(numel)` here, never a SharedArrayBuffer view. The
|
|
91
|
+
// narrower type lets the result flow into `Tensor.fromTypedArray` without
|
|
92
|
+
// a downstream cast.
|
|
93
|
+
export function preprocessFrame(source) {
|
|
94
|
+
const ctx = getPreprocessContext();
|
|
95
|
+
ctx.drawImage(source, 0, 0, DOC_DETECT_INPUT_SIZE, DOC_DETECT_INPUT_SIZE);
|
|
96
|
+
const pixels = ctx.getImageData(0, 0, DOC_DETECT_INPUT_SIZE, DOC_DETECT_INPUT_SIZE).data;
|
|
97
|
+
const out = new Uint8Array(DOC_DETECT_INPUT_SIZE * DOC_DETECT_INPUT_SIZE * 3);
|
|
98
|
+
for (let i = 0, j = 0; i < pixels.length; i += 4, j += 3) {
|
|
99
|
+
out[j] = pixels[i];
|
|
100
|
+
out[j + 1] = pixels[i + 1];
|
|
101
|
+
out[j + 2] = pixels[i + 2];
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function iou(ay0, ax0, ay1, ax1, by0, bx0, by1, bx1) {
|
|
106
|
+
const interY0 = Math.max(ay0, by0);
|
|
107
|
+
const interX0 = Math.max(ax0, bx0);
|
|
108
|
+
const interY1 = Math.min(ay1, by1);
|
|
109
|
+
const interX1 = Math.min(ax1, bx1);
|
|
110
|
+
const interW = Math.max(0, interX1 - interX0);
|
|
111
|
+
const interH = Math.max(0, interY1 - interY0);
|
|
112
|
+
const inter = interW * interH;
|
|
113
|
+
const aArea = Math.max(0, ax1 - ax0) * Math.max(0, ay1 - ay0);
|
|
114
|
+
const bArea = Math.max(0, bx1 - bx0) * Math.max(0, by1 - by0);
|
|
115
|
+
const union = aArea + bArea - inter;
|
|
116
|
+
return union <= 0 ? 0 : inter / union;
|
|
117
|
+
}
|
|
118
|
+
// Decode the three raw SSD outputs into a final detection list. Skips class
|
|
119
|
+
// 0 (background); reads class scores directly (sigmoid is baked into the
|
|
120
|
+
// model graph); applies per-class NMS.
|
|
121
|
+
export function decodeRawDetections(outputs, options) {
|
|
122
|
+
const scoreThreshold = options.scoreThreshold ?? 0.3;
|
|
123
|
+
const iouThreshold = options.iouThreshold ?? 0.5;
|
|
124
|
+
const [yScale, xScale, hScale, wScale] = options.scaleFactors ?? DEFAULT_SCALE_FACTORS;
|
|
125
|
+
const anchors = outputs.anchors;
|
|
126
|
+
const numAnchors = anchors.length / 4;
|
|
127
|
+
if (outputs.boxEncodings.length !== numAnchors * 4)
|
|
128
|
+
return [];
|
|
129
|
+
if (outputs.classPredictions.length % numAnchors !== 0)
|
|
130
|
+
return [];
|
|
131
|
+
const numClasses = outputs.classPredictions.length / numAnchors;
|
|
132
|
+
// Decode all anchor boxes up-front; per-class NMS reuses these.
|
|
133
|
+
const decoded = new Float32Array(numAnchors * 4);
|
|
134
|
+
for (let i = 0; i < numAnchors; i++) {
|
|
135
|
+
const ay = anchors[i * 4];
|
|
136
|
+
const ax = anchors[i * 4 + 1];
|
|
137
|
+
const ah = anchors[i * 4 + 2];
|
|
138
|
+
const aw = anchors[i * 4 + 3];
|
|
139
|
+
const ty = outputs.boxEncodings[i * 4];
|
|
140
|
+
const tx = outputs.boxEncodings[i * 4 + 1];
|
|
141
|
+
const th = outputs.boxEncodings[i * 4 + 2];
|
|
142
|
+
const tw = outputs.boxEncodings[i * 4 + 3];
|
|
143
|
+
const w = Math.exp(tw / wScale) * aw;
|
|
144
|
+
const h = Math.exp(th / hScale) * ah;
|
|
145
|
+
const yc = (ty / yScale) * ah + ay;
|
|
146
|
+
const xc = (tx / xScale) * aw + ax;
|
|
147
|
+
decoded[i * 4] = yc - h / 2;
|
|
148
|
+
decoded[i * 4 + 1] = xc - w / 2;
|
|
149
|
+
decoded[i * 4 + 2] = yc + h / 2;
|
|
150
|
+
decoded[i * 4 + 3] = xc + w / 2;
|
|
151
|
+
}
|
|
152
|
+
// Per-class NMS. Class 0 is background; classes 1..numClasses-1 are real
|
|
153
|
+
// and align with the 1-based DOC_DETECT_LABEL_MAP.
|
|
154
|
+
const detections = [];
|
|
155
|
+
for (let c = 1; c < numClasses; c++) {
|
|
156
|
+
const candidates = [];
|
|
157
|
+
for (let i = 0; i < numAnchors; i++) {
|
|
158
|
+
const score = outputs.classPredictions[i * numClasses + c];
|
|
159
|
+
if (score >= scoreThreshold) {
|
|
160
|
+
candidates.push({ score, idx: i });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (candidates.length === 0)
|
|
164
|
+
continue;
|
|
165
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
166
|
+
const suppressed = new Array(candidates.length).fill(false);
|
|
167
|
+
const label = DOC_DETECT_LABEL_MAP[c] ?? `class_${c}`;
|
|
168
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
169
|
+
if (suppressed[i])
|
|
170
|
+
continue;
|
|
171
|
+
const ai = candidates[i].idx;
|
|
172
|
+
const ay0 = decoded[ai * 4];
|
|
173
|
+
const ax0 = decoded[ai * 4 + 1];
|
|
174
|
+
const ay1 = decoded[ai * 4 + 2];
|
|
175
|
+
const ax1 = decoded[ai * 4 + 3];
|
|
176
|
+
detections.push({
|
|
177
|
+
classId: c,
|
|
178
|
+
label,
|
|
179
|
+
score: candidates[i].score,
|
|
180
|
+
yMin: ay0,
|
|
181
|
+
xMin: ax0,
|
|
182
|
+
yMax: ay1,
|
|
183
|
+
xMax: ax1,
|
|
184
|
+
});
|
|
185
|
+
for (let j = i + 1; j < candidates.length; j++) {
|
|
186
|
+
if (suppressed[j])
|
|
187
|
+
continue;
|
|
188
|
+
const bi = candidates[j].idx;
|
|
189
|
+
if (iou(ay0, ax0, ay1, ax1, decoded[bi * 4], decoded[bi * 4 + 1], decoded[bi * 4 + 2], decoded[bi * 4 + 3]) > iouThreshold) {
|
|
190
|
+
suppressed[j] = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
detections.sort((a, b) => b.score - a.score);
|
|
196
|
+
return detections;
|
|
197
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Detection } from "./blazeFacePrePost";
|
|
2
|
+
export declare const FACE_MESH_INPUT_SIZE = 192;
|
|
3
|
+
export declare const NUM_FACE_LANDMARKS = 468;
|
|
4
|
+
export type FaceMeshPreprocessResult = {
|
|
5
|
+
data: Float32Array;
|
|
6
|
+
roiX: number;
|
|
7
|
+
roiY: number;
|
|
8
|
+
roiSize: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function preprocessFaceROI(source: HTMLVideoElement | HTMLCanvasElement, detection: Detection): FaceMeshPreprocessResult;
|
|
11
|
+
export type FaceLandmark = {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
};
|
|
16
|
+
export type DecodeFaceLandmarksOptions = {
|
|
17
|
+
preprocess: FaceMeshPreprocessResult;
|
|
18
|
+
videoWidth: number;
|
|
19
|
+
videoHeight: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function decodeFaceLandmarks(raw: Float32Array, options: DecodeFaceLandmarksOptions): FaceLandmark[];
|
|
22
|
+
export declare function decodeFacePresence(raw: Float32Array): number;
|
|
23
|
+
//# sourceMappingURL=faceMeshPrePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faceMeshPrePost.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/litert/faceMeshPrePost.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAmBtC,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,YAAY,CAAC;IAGnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,EAC5C,SAAS,EAAE,SAAS,GACnB,wBAAwB,CAwD1B;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,wBAAwB,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,0BAA0B,GAClC,YAAY,EAAE,CAiBhB;AASD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAE5D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Pre/post-processing for the standalone `face_landmark.tflite` (468 points).
|
|
2
|
+
//
|
|
3
|
+
// MediaPipe's face_landmarker pipeline computes a rotation-corrected ROI from
|
|
4
|
+
// the BlazeFace detection and feeds a 192×192 crop into the landmarker. We
|
|
5
|
+
// approximate that here without rotation: a square crop centered on the
|
|
6
|
+
// detection bbox, scaled by ROI_PADDING_SCALE so the model sees forehead and
|
|
7
|
+
// chin margins it was trained on. Skipping rotation keeps the math simple and
|
|
8
|
+
// is acceptable for a diagnostic — landmarks drift visibly when the head tilts
|
|
9
|
+
// past ~20°, which is itself a useful signal for the non-starter watch list.
|
|
10
|
+
export const FACE_MESH_INPUT_SIZE = 192;
|
|
11
|
+
export const NUM_FACE_LANDMARKS = 468;
|
|
12
|
+
const ROI_PADDING_SCALE = 1.5;
|
|
13
|
+
let preprocessCanvas = null;
|
|
14
|
+
let preprocessCtx = null;
|
|
15
|
+
function getPreprocessContext() {
|
|
16
|
+
if (!preprocessCtx) {
|
|
17
|
+
preprocessCanvas = document.createElement("canvas");
|
|
18
|
+
preprocessCanvas.width = FACE_MESH_INPUT_SIZE;
|
|
19
|
+
preprocessCanvas.height = FACE_MESH_INPUT_SIZE;
|
|
20
|
+
const ctx = preprocessCanvas.getContext("2d", { willReadFrequently: true });
|
|
21
|
+
if (!ctx)
|
|
22
|
+
throw new Error("faceMeshPrePost: 2d context unavailable");
|
|
23
|
+
preprocessCtx = ctx;
|
|
24
|
+
}
|
|
25
|
+
return preprocessCtx;
|
|
26
|
+
}
|
|
27
|
+
export function preprocessFaceROI(source, detection) {
|
|
28
|
+
const ctx = getPreprocessContext();
|
|
29
|
+
const sw = source instanceof HTMLVideoElement ? source.videoWidth : source.width;
|
|
30
|
+
const sh = source instanceof HTMLVideoElement ? source.videoHeight : source.height;
|
|
31
|
+
const cx = ((detection.xMin + detection.xMax) / 2) * sw;
|
|
32
|
+
const cy = ((detection.yMin + detection.yMax) / 2) * sh;
|
|
33
|
+
const widthPx = (detection.xMax - detection.xMin) * sw;
|
|
34
|
+
const heightPx = (detection.yMax - detection.yMin) * sh;
|
|
35
|
+
const baseSizePx = Math.max(widthPx, heightPx);
|
|
36
|
+
const roiSizePx = baseSizePx * ROI_PADDING_SCALE;
|
|
37
|
+
// ROI in source pixel coords (may extend past the frame; ctx.drawImage
|
|
38
|
+
// handles clipping by leaving sampled pixels black, which approximates
|
|
39
|
+
// MediaPipe's letterbox behavior).
|
|
40
|
+
const roiX = cx - roiSizePx / 2;
|
|
41
|
+
const roiY = cy - roiSizePx / 2;
|
|
42
|
+
ctx.fillStyle = "black";
|
|
43
|
+
ctx.fillRect(0, 0, FACE_MESH_INPUT_SIZE, FACE_MESH_INPUT_SIZE);
|
|
44
|
+
ctx.drawImage(source, roiX, roiY, roiSizePx, roiSizePx, 0, 0, FACE_MESH_INPUT_SIZE, FACE_MESH_INPUT_SIZE);
|
|
45
|
+
const imageData = ctx.getImageData(0, 0, FACE_MESH_INPUT_SIZE, FACE_MESH_INPUT_SIZE);
|
|
46
|
+
const pixels = imageData.data;
|
|
47
|
+
const out = new Float32Array(FACE_MESH_INPUT_SIZE * FACE_MESH_INPUT_SIZE * 3);
|
|
48
|
+
// face_landmark.tflite expects [0, 1] normalized input.
|
|
49
|
+
for (let i = 0, j = 0; i < pixels.length; i += 4, j += 3) {
|
|
50
|
+
out[j] = pixels[i] / 255;
|
|
51
|
+
out[j + 1] = pixels[i + 1] / 255;
|
|
52
|
+
out[j + 2] = pixels[i + 2] / 255;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
data: out,
|
|
56
|
+
roiX: roiX / sw,
|
|
57
|
+
roiY: roiY / sh,
|
|
58
|
+
roiSize: roiSizePx,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function decodeFaceLandmarks(raw, options) {
|
|
62
|
+
const { preprocess, videoWidth, videoHeight } = options;
|
|
63
|
+
const landmarks = new Array(NUM_FACE_LANDMARKS);
|
|
64
|
+
const roiToSrcX = preprocess.roiSize / videoWidth;
|
|
65
|
+
const roiToSrcY = preprocess.roiSize / videoHeight;
|
|
66
|
+
for (let i = 0; i < NUM_FACE_LANDMARKS; i++) {
|
|
67
|
+
const px = raw[i * 3] / FACE_MESH_INPUT_SIZE;
|
|
68
|
+
const py = raw[i * 3 + 1] / FACE_MESH_INPUT_SIZE;
|
|
69
|
+
const pz = raw[i * 3 + 2];
|
|
70
|
+
landmarks[i] = {
|
|
71
|
+
x: preprocess.roiX + px * roiToSrcX,
|
|
72
|
+
y: preprocess.roiY + py * roiToSrcY,
|
|
73
|
+
z: pz,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return landmarks;
|
|
77
|
+
}
|
|
78
|
+
function sigmoid(x) {
|
|
79
|
+
const clipped = Math.max(-100, Math.min(100, x));
|
|
80
|
+
return 1 / (1 + Math.exp(-clipped));
|
|
81
|
+
}
|
|
82
|
+
// face_landmark.tflite emits a face-presence flag as a logit (single value).
|
|
83
|
+
// Apply sigmoid for a 0-1 confidence.
|
|
84
|
+
export function decodeFacePresence(raw) {
|
|
85
|
+
return sigmoid(raw[0]);
|
|
86
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const FOCUS_INPUT_SIZE = 224;
|
|
2
|
+
export declare const FOCUS_FOCUSED_INDEX = 1;
|
|
3
|
+
export declare function resizeAndExtractRgb(source: HTMLCanvasElement): Uint8Array<ArrayBuffer>;
|
|
4
|
+
export declare function normalizePixelsToFloat32(pixels: Uint8Array): Float32Array<ArrayBuffer>;
|
|
5
|
+
export declare function decodeFocusScore(output: Float32Array): number;
|
|
6
|
+
//# sourceMappingURL=focusPrePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focusPrePost.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/litert/focusPrePost.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAwBpC,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GACxB,UAAU,CAAC,WAAW,CAAC,CAWzB;AAOD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,UAAU,GACjB,YAAY,CAAC,WAAW,CAAC,CAM3B;AAKD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Pre/post-processing for the LiteRT focus classifier.
|
|
2
|
+
//
|
|
3
|
+
// Input contract:
|
|
4
|
+
// `input` — float32 [1, 224, 224, 3], stretch-resized RGB, normalized as
|
|
5
|
+
// `(px / 127.5) - 1` mapping pixel bytes [0, 255] to [-1, 1]. ML team
|
|
6
|
+
// confirmed the normalization on 2026-05-28.
|
|
7
|
+
//
|
|
8
|
+
// Output contract:
|
|
9
|
+
// `output` — float32 [1, 2] with softmax already applied inside the model
|
|
10
|
+
// graph. Index 1 is the "focused" class probability; index 0 is the
|
|
11
|
+
// complementary "not focused" probability. Do NOT re-apply softmax.
|
|
12
|
+
//
|
|
13
|
+
// If the ML team re-exports the model with a different input shape or class
|
|
14
|
+
// ordering, both FOCUS_INPUT_SIZE and FOCUS_FOCUSED_INDEX need updating.
|
|
15
|
+
export const FOCUS_INPUT_SIZE = 224;
|
|
16
|
+
export const FOCUS_FOCUSED_INDEX = 1;
|
|
17
|
+
let preprocessCanvas = null;
|
|
18
|
+
let preprocessCtx = null;
|
|
19
|
+
function getPreprocessContext() {
|
|
20
|
+
if (!preprocessCtx) {
|
|
21
|
+
preprocessCanvas = document.createElement('canvas');
|
|
22
|
+
preprocessCanvas.width = FOCUS_INPUT_SIZE;
|
|
23
|
+
preprocessCanvas.height = FOCUS_INPUT_SIZE;
|
|
24
|
+
const ctx = preprocessCanvas.getContext('2d', { willReadFrequently: true });
|
|
25
|
+
if (!ctx)
|
|
26
|
+
throw new Error('focusPrePost: 2d context unavailable');
|
|
27
|
+
preprocessCtx = ctx;
|
|
28
|
+
}
|
|
29
|
+
return preprocessCtx;
|
|
30
|
+
}
|
|
31
|
+
// Stretch-resize source into a 224×224 RGB uint8 buffer (alpha stripped).
|
|
32
|
+
//
|
|
33
|
+
// Return type narrows to `Uint8Array<ArrayBuffer>` (not the default
|
|
34
|
+
// `Uint8Array<ArrayBufferLike>`) because we always allocate a fresh
|
|
35
|
+
// `new Uint8Array(numel)` here, never a SharedArrayBuffer view. The
|
|
36
|
+
// narrower type lets the result flow into normalizePixelsToFloat32 and
|
|
37
|
+
// `Tensor.fromTypedArray` without a downstream cast.
|
|
38
|
+
export function resizeAndExtractRgb(source) {
|
|
39
|
+
const ctx = getPreprocessContext();
|
|
40
|
+
ctx.drawImage(source, 0, 0, FOCUS_INPUT_SIZE, FOCUS_INPUT_SIZE);
|
|
41
|
+
const pixels = ctx.getImageData(0, 0, FOCUS_INPUT_SIZE, FOCUS_INPUT_SIZE).data;
|
|
42
|
+
const out = new Uint8Array(FOCUS_INPUT_SIZE * FOCUS_INPUT_SIZE * 3);
|
|
43
|
+
for (let i = 0, j = 0; i < pixels.length; i += 4, j += 3) {
|
|
44
|
+
out[j] = pixels[i];
|
|
45
|
+
out[j + 1] = pixels[i + 1];
|
|
46
|
+
out[j + 2] = pixels[i + 2];
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
// Apply `(px / 127.5) - 1` per element, mapping [0, 255] → [-1, 1].
|
|
51
|
+
//
|
|
52
|
+
// Returns `Float32Array<ArrayBuffer>` (not the default `<ArrayBufferLike>`)
|
|
53
|
+
// for the same reason as resizeAndExtractRgb — always a fresh allocation,
|
|
54
|
+
// never a SharedArrayBuffer view.
|
|
55
|
+
export function normalizePixelsToFloat32(pixels) {
|
|
56
|
+
const out = new Float32Array(pixels.length);
|
|
57
|
+
for (let i = 0; i < pixels.length; i++) {
|
|
58
|
+
out[i] = pixels[i] / 127.5 - 1;
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
// Read the "focused" class probability. The model graph already applies
|
|
63
|
+
// softmax, so `output[FOCUS_FOCUSED_INDEX]` is already in [0, 1] and can be
|
|
64
|
+
// returned directly. Returns 0 when output is empty (defensive).
|
|
65
|
+
export function decodeFocusScore(output) {
|
|
66
|
+
return output[FOCUS_FOCUSED_INDEX] ?? 0;
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CompiledModel } from '@litertjs/core';
|
|
2
|
+
export declare const LITERT_WASM_DIR = "https://websdk-cdn-dev.idmission.com/assets/litert/2.5.1/wasm/";
|
|
3
|
+
export declare function ensureLiteRtLoaded(): Promise<void>;
|
|
4
|
+
export type AcceleratorChoice = 'webgpu' | 'wasm' | 'auto';
|
|
5
|
+
export type ResolvedAccelerator = 'webgpu' | 'wasm';
|
|
6
|
+
export declare function resolveAccelerator(choice: AcceleratorChoice): ResolvedAccelerator;
|
|
7
|
+
export type LoadModelResult = {
|
|
8
|
+
model: CompiledModel;
|
|
9
|
+
resolvedAccelerator: ResolvedAccelerator;
|
|
10
|
+
loadMs: number;
|
|
11
|
+
};
|
|
12
|
+
export type ModelSource = string | URL | Uint8Array;
|
|
13
|
+
export declare function loadModel(source: ModelSource, choice: AcceleratorChoice): Promise<LoadModelResult>;
|
|
14
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/litert/runtime.ts"],"names":[],"mappings":"AASA,OAAO,EACL,aAAa,EAId,MAAM,gBAAgB,CAAA;AAOvB,eAAO,MAAM,eAAe,mEAAsD,CAAA;AAIlF,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAgBlD;AAED,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;AAC1D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEnD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,iBAAiB,GACxB,mBAAmB,CAGrB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,aAAa,CAAA;IACpB,mBAAmB,EAAE,mBAAmB,CAAA;IACxC,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,GAAG,GAAG,UAAU,CAAA;AAInD,wBAAsB,SAAS,CAC7B,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,eAAe,CAAC,CA8B1B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Thin wrapper around @litertjs/core for the LiteRT-backed providers.
|
|
2
|
+
//
|
|
3
|
+
// `loadLiteRt` initializes the global LiteRT WASM module (one-time per page).
|
|
4
|
+
// Subsequent model loads share the global instance. The WASM files are served
|
|
5
|
+
// from the SDK's own CloudFront CDN (alongside the .tflite models), pinned to
|
|
6
|
+
// `LITERT_VERSION` so the runtime bytes match the installed @litertjs/core npm
|
|
7
|
+
// bindings. Upload them with `scripts/setlitertwasm.sh` whenever the version
|
|
8
|
+
// here changes.
|
|
9
|
+
import { isWebGPUSupported, loadAndCompile, loadLiteRt, } from '@litertjs/core';
|
|
10
|
+
import { DEFAULT_CDN_URL } from '../../../config/cdn';
|
|
11
|
+
import { withQuietWasm } from '../../VisionRuntime';
|
|
12
|
+
// Keep in sync with the installed @litertjs/core version in package.json; the
|
|
13
|
+
// CDN-hosted WASM runtime must match the bundled JS bindings.
|
|
14
|
+
const LITERT_VERSION = '2.5.1';
|
|
15
|
+
export const LITERT_WASM_DIR = `${DEFAULT_CDN_URL}/litert/${LITERT_VERSION}/wasm/`;
|
|
16
|
+
let runtimePromise = null;
|
|
17
|
+
export function ensureLiteRtLoaded() {
|
|
18
|
+
if (!runtimePromise) {
|
|
19
|
+
// Quiet scope covers the load, not just the later compiles: creating the
|
|
20
|
+
// default environment registers the WebGPU/CPU accelerators, and each
|
|
21
|
+
// registration logs through Emscripten's stderr.
|
|
22
|
+
runtimePromise = withQuietWasm(() => loadLiteRt(LITERT_WASM_DIR)).then(() => undefined, (err) => {
|
|
23
|
+
// Clear the cache on rejection so the next caller gets a fresh attempt
|
|
24
|
+
// instead of the stuck rejection.
|
|
25
|
+
runtimePromise = null;
|
|
26
|
+
throw err;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return runtimePromise;
|
|
30
|
+
}
|
|
31
|
+
export function resolveAccelerator(choice) {
|
|
32
|
+
if (choice === 'auto')
|
|
33
|
+
return isWebGPUSupported() ? 'webgpu' : 'wasm';
|
|
34
|
+
return choice;
|
|
35
|
+
}
|
|
36
|
+
// Load and compile a .tflite. Accepts either a URL (LiteRT fetches) or a
|
|
37
|
+
// Uint8Array (SRI-validated bytes from preloadDependency). Caller decides.
|
|
38
|
+
export async function loadModel(source, choice) {
|
|
39
|
+
await ensureLiteRtLoaded();
|
|
40
|
+
const resolvedAccelerator = resolveAccelerator(choice);
|
|
41
|
+
const t0 = performance.now();
|
|
42
|
+
let model;
|
|
43
|
+
try {
|
|
44
|
+
model = await withQuietWasm(() => loadAndCompile(source, { accelerator: resolvedAccelerator }));
|
|
45
|
+
}
|
|
46
|
+
catch (cause) {
|
|
47
|
+
// LiteRT's own failure is `Failed to load model from buffer` with a stack
|
|
48
|
+
// of wasm-function frames and NOTHING identifying the model — the bytes
|
|
49
|
+
// are already in WASM by then, so the URL is not in the message, the
|
|
50
|
+
// stack, or anything downstream. That leaves an integrator unable to tell
|
|
51
|
+
// "our default model is broken" from "the model URL I pinned in 2.x is a
|
|
52
|
+
// MediaPipe export and this is the LiteRT runtime", which are opposite
|
|
53
|
+
// problems with opposite fixes. Re-thrown with the source attached, and
|
|
54
|
+
// `cause` preserved so the WASM stack survives.
|
|
55
|
+
throw new Error(`LiteRT failed to compile the model at ${describeModelSource(source)} ` +
|
|
56
|
+
`(accelerator: ${resolvedAccelerator}). If this URL was set explicitly, ` +
|
|
57
|
+
`check it is a LiteRT export rather than a MediaPipe one — the two are ` +
|
|
58
|
+
`not interchangeable and the runtime defaults to LiteRT.`, { cause });
|
|
59
|
+
}
|
|
60
|
+
const loadMs = performance.now() - t0;
|
|
61
|
+
return { model, resolvedAccelerator, loadMs };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Origin + pathname only. The model path is caller-supplied and may be a
|
|
65
|
+
* signed URL, where the signature lives in the query string and credentials
|
|
66
|
+
* can live in the userinfo — neither belongs in a console line or in an
|
|
67
|
+
* `Error` handed to a host's error handler. `URL.origin` excludes userinfo by
|
|
68
|
+
* construction, and dropping the query costs nothing diagnostically: the
|
|
69
|
+
* pathname is the part that says WHICH model.
|
|
70
|
+
*/
|
|
71
|
+
function describeModelSource(source) {
|
|
72
|
+
if (source instanceof Uint8Array)
|
|
73
|
+
return `<${source.byteLength} preloaded bytes>`;
|
|
74
|
+
try {
|
|
75
|
+
const base = typeof location === 'undefined' ? undefined : location.href;
|
|
76
|
+
const url = new URL(String(source), base);
|
|
77
|
+
return url.origin + url.pathname;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// A relative path with no document to resolve against (Node, workers).
|
|
81
|
+
return '<model source>';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Frame } from '../../../utils/getFrameDimensions';
|
|
2
|
+
import { DetectedObjectBox } from '../../DocumentDetection';
|
|
3
|
+
import type { BarcodeReadabilityPrediction } from '../../BarcodeReadability';
|
|
4
|
+
export type LoadOptions = {
|
|
5
|
+
modelAssetPath: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function load({ modelAssetPath }: LoadOptions): Promise<void>;
|
|
8
|
+
export declare function predict(imageData: Frame, cropCanvas: HTMLCanvasElement, rotateCanvas: HTMLCanvasElement, resizeCanvas: HTMLCanvasElement, box?: DetectedObjectBox): BarcodeReadabilityPrediction | null;
|
|
9
|
+
export declare function classifyForVideo(frame: Frame): void;
|
|
10
|
+
export declare function close(): void;
|
|
11
|
+
//# sourceMappingURL=BarcodeReadability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarcodeReadability.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/mediapipe/BarcodeReadability.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAO3D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAA;AAK5E,MAAM,MAAM,WAAW,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpD,wBAAsB,IAAI,CAAC,EAAE,cAAc,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BzE;AAcD,wBAAgB,OAAO,CACrB,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,iBAAiB,EAC/B,YAAY,EAAE,iBAAiB,EAC/B,GAAG,CAAC,EAAE,iBAAiB,GACtB,4BAA4B,GAAG,IAAI,CA2BrC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAInD;AAED,wBAAgB,KAAK,IAAI,IAAI,CAI5B"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { FilesetResolver, ImageClassifier } from '@mediapipe/tasks-vision';
|
|
2
|
+
import { getDelegate } from '../../CapabilityProbing';
|
|
3
|
+
const RUNTIME = 'mediapipe';
|
|
4
|
+
import { visionTasksBasePath, withQuietWasm, withQuietWasmSync, } from '../../VisionRuntime';
|
|
5
|
+
import { cropAndRotateIfNecessary, resizeIfNecessary, } from '../../../utils/cropping';
|
|
6
|
+
import { debug } from '../../../utils/logger';
|
|
7
|
+
import { getCachedModelBuffer } from '../../preloadModels';
|
|
8
|
+
let classifier = null;
|
|
9
|
+
let classifierSettings = null;
|
|
10
|
+
export async function load({ modelAssetPath }) {
|
|
11
|
+
if (classifier && classifierSettings?.modelAssetPath === modelAssetPath)
|
|
12
|
+
return;
|
|
13
|
+
close();
|
|
14
|
+
if (getDelegate(RUNTIME) === 'NONE') {
|
|
15
|
+
throw new Error('No available delegate for barcode readability model.');
|
|
16
|
+
}
|
|
17
|
+
const cachedBuffer = getCachedModelBuffer(modelAssetPath);
|
|
18
|
+
classifier = await withQuietWasm(async () => ImageClassifier.createFromOptions(await FilesetResolver.forVisionTasks(visionTasksBasePath), {
|
|
19
|
+
baseOptions: {
|
|
20
|
+
...(cachedBuffer
|
|
21
|
+
? { modelAssetBuffer: cachedBuffer }
|
|
22
|
+
: { modelAssetPath }),
|
|
23
|
+
delegate: 'CPU',
|
|
24
|
+
},
|
|
25
|
+
runningMode: 'VIDEO',
|
|
26
|
+
maxResults: 1,
|
|
27
|
+
}));
|
|
28
|
+
classifierSettings = { modelAssetPath };
|
|
29
|
+
}
|
|
30
|
+
// Minimum box size (in pixels) before we'll attempt a readability
|
|
31
|
+
// prediction. Sub-pixel widths get truncated to 0 by HTMLCanvasElement,
|
|
32
|
+
// producing an empty canvas that MediaPipe's classifyForVideo rejects
|
|
33
|
+
// (`texImage2D: no canvas`) and OpenCV's internal warpPerspective trips
|
|
34
|
+
// (`_src.total() > 0`). The LiteRT document detector occasionally emits
|
|
35
|
+
// barcode-class detections whose normalized coords clip near a frame
|
|
36
|
+
// edge, yielding a sliver box that survives the adapter's `width <= 0`
|
|
37
|
+
// filter but still produces an unusable crop. 8px is large enough to
|
|
38
|
+
// guarantee a valid texture upload and small enough that no real
|
|
39
|
+
// barcode/face/etc. detection should ever be below it.
|
|
40
|
+
const MIN_PREDICT_BOX_PX = 8;
|
|
41
|
+
export function predict(imageData, cropCanvas, rotateCanvas, resizeCanvas, box) {
|
|
42
|
+
const c = classifier;
|
|
43
|
+
if (!c)
|
|
44
|
+
return null;
|
|
45
|
+
if (box &&
|
|
46
|
+
(box.width < MIN_PREDICT_BOX_PX || box.height < MIN_PREDICT_BOX_PX)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const startedAt = performance.now();
|
|
50
|
+
const image = cropAndRotateIfNecessary(imageData, cropCanvas, rotateCanvas, box);
|
|
51
|
+
const resized = resizeIfNecessary(image, resizeCanvas, 500);
|
|
52
|
+
const result = withQuietWasmSync(() => c.classifyForVideo(resized, performance.now()));
|
|
53
|
+
const score = result?.classifications?.[0]?.categories?.find((c) => c.categoryName === 'blurry')?.score ?? 0;
|
|
54
|
+
debug('barcode prediction', `${performance.now() - startedAt}ms`, score);
|
|
55
|
+
const predictionTime = performance.now() - startedAt;
|
|
56
|
+
return { score, predictionTime };
|
|
57
|
+
}
|
|
58
|
+
export function classifyForVideo(frame) {
|
|
59
|
+
const c = classifier;
|
|
60
|
+
if (!c)
|
|
61
|
+
return;
|
|
62
|
+
withQuietWasmSync(() => c.classifyForVideo(frame, performance.now()));
|
|
63
|
+
}
|
|
64
|
+
export function close() {
|
|
65
|
+
classifier?.close();
|
|
66
|
+
classifier = null;
|
|
67
|
+
classifierSettings = null;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityProbe.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/mediapipe/CapabilityProbe.ts"],"names":[],"mappings":"AASA,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,KAAK,GAAG,KAAK,EACvB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FilesetResolver, ImageSegmenter } from '@mediapipe/tasks-vision';
|
|
2
|
+
import { visionTasksBasePath, withQuietWasm } from '../../VisionRuntime';
|
|
3
|
+
// Verify a given delegate (GPU or CPU) can actually run a TFLite model in this
|
|
4
|
+
// browser. Creates an ImageSegmenter, runs it once against an empty canvas,
|
|
5
|
+
// and lets any thrown error propagate up so the caller can fall back. We
|
|
6
|
+
// intentionally don't close the segmenter or remove the canvas to match the
|
|
7
|
+
// pre-refactor behavior — changing that mid-refactor would conflate two
|
|
8
|
+
// concerns.
|
|
9
|
+
export async function verifyMediaPipeDelegate(delegate, modelAssetPath) {
|
|
10
|
+
const model = await withQuietWasm(async () => ImageSegmenter.createFromOptions(await FilesetResolver.forVisionTasks(visionTasksBasePath), { baseOptions: { modelAssetPath, delegate } }));
|
|
11
|
+
const emptyFrame = document.createElement('canvas');
|
|
12
|
+
model.segment(emptyFrame);
|
|
13
|
+
emptyFrame.remove();
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ObjectDetector } from '@mediapipe/tasks-vision';
|
|
2
|
+
import type { ObjectDetectorPrediction } from '../../DocumentDetection';
|
|
3
|
+
export type LoadOptions = {
|
|
4
|
+
modelAssetPath: string;
|
|
5
|
+
scoreThreshold: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function load({ modelAssetPath, scoreThreshold, }: LoadOptions): Promise<void>;
|
|
8
|
+
export declare function predict(frame: HTMLCanvasElement): Promise<ObjectDetectorPrediction | null>;
|
|
9
|
+
export declare function getRawDetector(): ObjectDetector | null;
|
|
10
|
+
export declare function close(): void;
|
|
11
|
+
export declare function testAgainstKnownImage(): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=DocumentDetection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentDetection.d.ts","sourceRoot":"","sources":["../../../../src/models/providers/mediapipe/DocumentDetection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAYzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAQvE,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,wBAAsB,IAAI,CAAC,EACzB,cAAc,EACd,cAAc,GACf,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC7B;AAED,wBAAsB,OAAO,CAC3B,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAuB1C;AAED,wBAAgB,cAAc,IAAI,cAAc,GAAG,IAAI,CAEtD;AAED,wBAAgB,KAAK,IAAI,IAAI,CAI5B;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAmC3D"}
|