idmission-web-sdk 2.2.30 → 2.2.32
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/dist/components/id_capture/DocumentDetectionModelProvider.d.ts.map +1 -1
- package/dist/components/id_capture/FocusModelProvider.d.ts.map +1 -1
- package/dist/components/selfie_capture/SelfieGuidanceModelsProvider.d.ts.map +1 -1
- package/dist/lib/models/DocumentDetection.d.ts +2 -3
- package/dist/lib/models/DocumentDetection.d.ts.map +1 -1
- package/dist/lib/models/FaceDetection.d.ts +3 -4
- package/dist/lib/models/FaceDetection.d.ts.map +1 -1
- package/dist/lib/models/Focus.d.ts +2 -3
- package/dist/lib/models/Focus.d.ts.map +1 -1
- package/dist/lib/models/preloadModels.d.ts.map +1 -1
- package/dist/sdk2.cjs.development.js +114 -124
- package/dist/sdk2.cjs.development.js.map +1 -1
- package/dist/sdk2.cjs.production.js +1 -1
- package/dist/sdk2.cjs.production.js.map +1 -1
- package/dist/sdk2.esm.js +114 -124
- package/dist/sdk2.esm.js.map +1 -1
- package/dist/sdk2.umd.development.js +114 -124
- package/dist/sdk2.umd.development.js.map +1 -1
- package/dist/sdk2.umd.production.js +1 -1
- package/dist/sdk2.umd.production.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -3
package/dist/sdk2.esm.js
CHANGED
|
@@ -201,7 +201,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
201
201
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
var webSdkVersion = '2.2.
|
|
204
|
+
var webSdkVersion = '2.2.32';
|
|
205
205
|
|
|
206
206
|
function getPlatform() {
|
|
207
207
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -2783,30 +2783,29 @@ var defaultFocusThresholds = {
|
|
|
2783
2783
|
mobile: 0.3
|
|
2784
2784
|
}
|
|
2785
2785
|
};
|
|
2786
|
-
var
|
|
2786
|
+
var classifier = null;
|
|
2787
|
+
var classifierSettings = null;
|
|
2787
2788
|
function loadFocusModel() {
|
|
2788
2789
|
return __awaiter(this, arguments, void 0, function (modelAssetPath) {
|
|
2789
|
-
var
|
|
2790
|
+
var _a, _b;
|
|
2790
2791
|
if (modelAssetPath === void 0) {
|
|
2791
2792
|
modelAssetPath = defaultFocusModelPath;
|
|
2792
2793
|
}
|
|
2793
|
-
return __generator(this, function (
|
|
2794
|
-
switch (
|
|
2794
|
+
return __generator(this, function (_c) {
|
|
2795
|
+
switch (_c.label) {
|
|
2795
2796
|
case 0:
|
|
2796
|
-
|
|
2797
|
-
|
|
2797
|
+
if (classifier && (classifierSettings === null || classifierSettings === void 0 ? void 0 : classifierSettings.modelAssetPath) === modelAssetPath) return [2 /*return*/, classifier];
|
|
2798
|
+
closeFocusModel();
|
|
2798
2799
|
return [4 /*yield*/, preloadFocusModelDependencies()];
|
|
2799
2800
|
case 1:
|
|
2800
|
-
|
|
2801
|
+
_c.sent();
|
|
2801
2802
|
if (modelCapabilities.delegate === 'NONE') {
|
|
2802
2803
|
throw new Error('No available delegate for focus detector.');
|
|
2803
2804
|
}
|
|
2804
|
-
_a =
|
|
2805
|
-
_b = id;
|
|
2806
|
-
_d = (_c = ImageClassifier).createFromOptions;
|
|
2805
|
+
_b = (_a = ImageClassifier).createFromOptions;
|
|
2807
2806
|
return [4 /*yield*/, FilesetResolver.forVisionTasks(visionTasksBasePath)];
|
|
2808
2807
|
case 2:
|
|
2809
|
-
return [4 /*yield*/,
|
|
2808
|
+
return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
|
|
2810
2809
|
baseOptions: {
|
|
2811
2810
|
modelAssetPath: modelAssetPath,
|
|
2812
2811
|
delegate: modelCapabilities.delegate
|
|
@@ -2815,20 +2814,19 @@ function loadFocusModel() {
|
|
|
2815
2814
|
runningMode: 'VIDEO'
|
|
2816
2815
|
}])];
|
|
2817
2816
|
case 3:
|
|
2818
|
-
|
|
2819
|
-
|
|
2817
|
+
classifier = _c.sent();
|
|
2818
|
+
classifierSettings = {
|
|
2819
|
+
modelAssetPath: modelAssetPath
|
|
2820
|
+
};
|
|
2821
|
+
return [2 /*return*/, classifier];
|
|
2820
2822
|
}
|
|
2821
2823
|
});
|
|
2822
2824
|
});
|
|
2823
2825
|
}
|
|
2824
|
-
function closeFocusModel(
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
var id = "".concat(modelAssetPath);
|
|
2829
|
-
if (!models[id]) return;
|
|
2830
|
-
models[id].close();
|
|
2831
|
-
delete models[id];
|
|
2826
|
+
function closeFocusModel() {
|
|
2827
|
+
classifier === null || classifier === void 0 ? void 0 : classifier.close();
|
|
2828
|
+
classifier = null;
|
|
2829
|
+
classifierSettings = null;
|
|
2832
2830
|
}
|
|
2833
2831
|
function useLoadFocusModel(_a) {
|
|
2834
2832
|
var _b = _a.modelPath,
|
|
@@ -2836,7 +2834,6 @@ function useLoadFocusModel(_a) {
|
|
|
2836
2834
|
_c = _a.modelLoadTimeoutMs,
|
|
2837
2835
|
modelLoadTimeoutMs = _c === void 0 ? defaultFocusModelLoadTimeoutMs : _c,
|
|
2838
2836
|
onModelError = _a.onModelError;
|
|
2839
|
-
var model = useRef(null);
|
|
2840
2837
|
var _d = useState(false),
|
|
2841
2838
|
ready = _d[0],
|
|
2842
2839
|
setReady = _d[1];
|
|
@@ -2862,7 +2859,6 @@ function useLoadFocusModel(_a) {
|
|
|
2862
2859
|
return __generator(this, function (_a) {
|
|
2863
2860
|
switch (_a.label) {
|
|
2864
2861
|
case 0:
|
|
2865
|
-
model.current = loadedModel;
|
|
2866
2862
|
setModelDownloadProgress(100);
|
|
2867
2863
|
clearTimeout(modelLoadTimeout);
|
|
2868
2864
|
return [4 /*yield*/, waitForVideoReady(videoRef)];
|
|
@@ -2882,9 +2878,8 @@ function useLoadFocusModel(_a) {
|
|
|
2882
2878
|
clearTimeout(modelLoadTimeout);
|
|
2883
2879
|
});
|
|
2884
2880
|
return function () {
|
|
2885
|
-
log('unloading focus model'
|
|
2886
|
-
|
|
2887
|
-
closeFocusModel(modelPath);
|
|
2881
|
+
log('unloading focus model');
|
|
2882
|
+
closeFocusModel();
|
|
2888
2883
|
clearTimeout(modelLoadTimeout);
|
|
2889
2884
|
document.removeEventListener('idmission.preloadProgress.focus', handleDownloadProgress);
|
|
2890
2885
|
};
|
|
@@ -2893,7 +2888,6 @@ function useLoadFocusModel(_a) {
|
|
|
2893
2888
|
modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
|
|
2894
2889
|
}, [modelError, onModelError]);
|
|
2895
2890
|
return {
|
|
2896
|
-
model: model,
|
|
2897
2891
|
ready: ready,
|
|
2898
2892
|
modelDownloadProgress: modelDownloadProgress,
|
|
2899
2893
|
modelError: modelError
|
|
@@ -2905,11 +2899,12 @@ function setLastFocusPredictionAt(time) {
|
|
|
2905
2899
|
lastFocusPredictionTime = time - lastFocusPredictionAt;
|
|
2906
2900
|
lastFocusPredictionAt = time;
|
|
2907
2901
|
}
|
|
2908
|
-
function makeFocusModelPrediction(
|
|
2902
|
+
function makeFocusModelPrediction(imageData, cropCanvas, rotateCanvas, box) {
|
|
2909
2903
|
var _a, _b, _c, _d, _e;
|
|
2904
|
+
if (!classifier) return null;
|
|
2910
2905
|
var startedAt = new Date();
|
|
2911
2906
|
var image = cropIfNecessary(imageData, cropCanvas, rotateCanvas, box);
|
|
2912
|
-
var result =
|
|
2907
|
+
var result = classifier.classifyForVideo(image, performance.now());
|
|
2913
2908
|
var score = (_e = (_d = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.classifications) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.categories) === null || _c === void 0 ? void 0 : _c.find(function (c) {
|
|
2914
2909
|
return c.categoryName === 'focused';
|
|
2915
2910
|
})) === null || _d === void 0 ? void 0 : _d.score) !== null && _e !== void 0 ? _e : 0;
|
|
@@ -2938,30 +2933,29 @@ function cropIfNecessary(imageData, cropCanvas, rotateCanvas, box) {
|
|
|
2938
2933
|
}
|
|
2939
2934
|
|
|
2940
2935
|
var defaultSelfieCaptureModelLoadTimeoutMs = 45000;
|
|
2941
|
-
var
|
|
2936
|
+
var detector$1 = null;
|
|
2937
|
+
var detectorSettings$1 = null;
|
|
2942
2938
|
function loadFaceDetector() {
|
|
2943
2939
|
return __awaiter(this, arguments, void 0, function (modelAssetPath) {
|
|
2944
|
-
var
|
|
2940
|
+
var _a, _b;
|
|
2945
2941
|
if (modelAssetPath === void 0) {
|
|
2946
2942
|
modelAssetPath = defaultFaceDetectorModelPath;
|
|
2947
2943
|
}
|
|
2948
|
-
return __generator(this, function (
|
|
2949
|
-
switch (
|
|
2944
|
+
return __generator(this, function (_c) {
|
|
2945
|
+
switch (_c.label) {
|
|
2950
2946
|
case 0:
|
|
2951
|
-
|
|
2952
|
-
|
|
2947
|
+
if (detector$1 && (detectorSettings$1 === null || detectorSettings$1 === void 0 ? void 0 : detectorSettings$1.modelAssetPath) === modelAssetPath) return [2 /*return*/, detector$1];
|
|
2948
|
+
closeFaceDetector();
|
|
2953
2949
|
return [4 /*yield*/, preloadFaceDetectorDependencies()];
|
|
2954
2950
|
case 1:
|
|
2955
|
-
|
|
2951
|
+
_c.sent();
|
|
2956
2952
|
if (modelCapabilities.delegate === 'NONE') {
|
|
2957
2953
|
throw new Error('No available delegate for face detector.');
|
|
2958
2954
|
}
|
|
2959
|
-
_a =
|
|
2960
|
-
_b = id;
|
|
2961
|
-
_d = (_c = FaceDetector).createFromOptions;
|
|
2955
|
+
_b = (_a = FaceDetector).createFromOptions;
|
|
2962
2956
|
return [4 /*yield*/, FilesetResolver.forVisionTasks(visionTasksBasePath)];
|
|
2963
2957
|
case 2:
|
|
2964
|
-
return [4 /*yield*/,
|
|
2958
|
+
return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
|
|
2965
2959
|
// canvas: document.createElement('canvas'),
|
|
2966
2960
|
baseOptions: {
|
|
2967
2961
|
modelAssetPath: modelAssetPath,
|
|
@@ -2970,26 +2964,24 @@ function loadFaceDetector() {
|
|
|
2970
2964
|
runningMode: 'VIDEO'
|
|
2971
2965
|
}])];
|
|
2972
2966
|
case 3:
|
|
2973
|
-
|
|
2974
|
-
|
|
2967
|
+
detector$1 = _c.sent();
|
|
2968
|
+
detectorSettings$1 = {
|
|
2969
|
+
modelAssetPath: modelAssetPath
|
|
2970
|
+
};
|
|
2971
|
+
return [2 /*return*/, detector$1];
|
|
2975
2972
|
}
|
|
2976
2973
|
});
|
|
2977
2974
|
});
|
|
2978
2975
|
}
|
|
2979
|
-
function closeFaceDetector(
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
var id = "".concat(modelAssetPath);
|
|
2984
|
-
if (!detectors$1[id]) return;
|
|
2985
|
-
detectors$1[id].close();
|
|
2986
|
-
delete detectors$1[id];
|
|
2976
|
+
function closeFaceDetector() {
|
|
2977
|
+
detector$1 === null || detector$1 === void 0 ? void 0 : detector$1.close();
|
|
2978
|
+
detector$1 = null;
|
|
2979
|
+
detectorSettings$1 = null;
|
|
2987
2980
|
}
|
|
2988
2981
|
function useLoadFaceDetector(_a) {
|
|
2989
2982
|
var onModelError = _a.onModelError,
|
|
2990
2983
|
_b = _a.modelLoadTimeoutMs,
|
|
2991
2984
|
modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b;
|
|
2992
|
-
var detector = useRef(null);
|
|
2993
2985
|
var _c = useState(false),
|
|
2994
2986
|
ready = _c[0],
|
|
2995
2987
|
setReady = _c[1];
|
|
@@ -3015,7 +3007,6 @@ function useLoadFaceDetector(_a) {
|
|
|
3015
3007
|
return __generator(this, function (_a) {
|
|
3016
3008
|
switch (_a.label) {
|
|
3017
3009
|
case 0:
|
|
3018
|
-
detector.current = model;
|
|
3019
3010
|
setModelDownloadProgress(100);
|
|
3020
3011
|
clearTimeout(modelLoadTimeout);
|
|
3021
3012
|
return [4 /*yield*/, waitForVideoReady(videoRef)];
|
|
@@ -3033,8 +3024,7 @@ function useLoadFaceDetector(_a) {
|
|
|
3033
3024
|
clearTimeout(modelLoadTimeout);
|
|
3034
3025
|
});
|
|
3035
3026
|
return function () {
|
|
3036
|
-
log('unloading face detection model'
|
|
3037
|
-
detector.current = null;
|
|
3027
|
+
log('unloading face detection model');
|
|
3038
3028
|
closeFaceDetector();
|
|
3039
3029
|
clearTimeout(modelLoadTimeout);
|
|
3040
3030
|
document.removeEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
|
|
@@ -3044,7 +3034,6 @@ function useLoadFaceDetector(_a) {
|
|
|
3044
3034
|
modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
|
|
3045
3035
|
}, [modelError, onModelError]);
|
|
3046
3036
|
return {
|
|
3047
|
-
detector: detector,
|
|
3048
3037
|
ready: ready,
|
|
3049
3038
|
modelDownloadProgress: modelDownloadProgress,
|
|
3050
3039
|
modelError: modelError
|
|
@@ -3083,8 +3072,9 @@ function trackFace(face, framesNeeded) {
|
|
|
3083
3072
|
if (lastNPairs$1.length > framesNeeded - 1) lastNPairs$1.length = framesNeeded - 1;
|
|
3084
3073
|
}
|
|
3085
3074
|
}
|
|
3086
|
-
function makeFaceDetectorPrediction(
|
|
3087
|
-
|
|
3075
|
+
function makeFaceDetectorPrediction(imageData) {
|
|
3076
|
+
if (!detector$1) return null;
|
|
3077
|
+
var prediction = detector$1.detectForVideo(imageData, performance.now());
|
|
3088
3078
|
var faces = prediction.detections.map(function (d) {
|
|
3089
3079
|
return {
|
|
3090
3080
|
box: convertBoundingBox(d.boundingBox),
|
|
@@ -3220,11 +3210,10 @@ var progressByUseCase = {
|
|
|
3220
3210
|
};
|
|
3221
3211
|
function preloadDependency(url) {
|
|
3222
3212
|
return __awaiter(this, void 0, void 0, function () {
|
|
3223
|
-
var xhr;
|
|
3224
3213
|
return __generator(this, function (_a) {
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3214
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
3215
|
+
var req = new XMLHttpRequest();
|
|
3216
|
+
req.addEventListener('progress', function (event) {
|
|
3228
3217
|
if (!event.lengthComputable) return;
|
|
3229
3218
|
progressByUrl[url] = event;
|
|
3230
3219
|
document.dispatchEvent(new CustomEvent('idmission.preloadProgress', {
|
|
@@ -3235,11 +3224,12 @@ function preloadDependency(url) {
|
|
|
3235
3224
|
}
|
|
3236
3225
|
}));
|
|
3237
3226
|
});
|
|
3238
|
-
|
|
3239
|
-
resolve(
|
|
3227
|
+
req.addEventListener('loadend', function () {
|
|
3228
|
+
resolve(req.readyState === 4 && req.status === 200);
|
|
3240
3229
|
});
|
|
3241
|
-
|
|
3242
|
-
|
|
3230
|
+
req.addEventListener('error', reject);
|
|
3231
|
+
req.open('GET', url, true);
|
|
3232
|
+
req.send();
|
|
3243
3233
|
})];
|
|
3244
3234
|
});
|
|
3245
3235
|
});
|
|
@@ -3262,8 +3252,11 @@ function preloadDocumentDetectorDependencies() {
|
|
|
3262
3252
|
switch (_a.label) {
|
|
3263
3253
|
case 0:
|
|
3264
3254
|
if (documentDetectorPreloading) return [2 /*return*/, new Promise(function (resolve) {
|
|
3265
|
-
setInterval(function () {
|
|
3266
|
-
if (!documentDetectorPreloading)
|
|
3255
|
+
var i = setInterval(function () {
|
|
3256
|
+
if (!documentDetectorPreloading) {
|
|
3257
|
+
clearInterval(i);
|
|
3258
|
+
resolve();
|
|
3259
|
+
}
|
|
3267
3260
|
}, 100);
|
|
3268
3261
|
})];
|
|
3269
3262
|
documentDetectorPreloading = true;
|
|
@@ -3307,8 +3300,11 @@ function preloadFocusModelDependencies() {
|
|
|
3307
3300
|
switch (_a.label) {
|
|
3308
3301
|
case 0:
|
|
3309
3302
|
if (focusModelPreloading) return [2 /*return*/, new Promise(function (resolve) {
|
|
3310
|
-
setInterval(function () {
|
|
3311
|
-
if (!focusModelPreloading)
|
|
3303
|
+
var i = setInterval(function () {
|
|
3304
|
+
if (!focusModelPreloading) {
|
|
3305
|
+
clearInterval(i);
|
|
3306
|
+
resolve();
|
|
3307
|
+
}
|
|
3312
3308
|
}, 100);
|
|
3313
3309
|
})];
|
|
3314
3310
|
focusModelPreloading = true;
|
|
@@ -3352,8 +3348,11 @@ function preloadFaceDetectorDependencies() {
|
|
|
3352
3348
|
switch (_a.label) {
|
|
3353
3349
|
case 0:
|
|
3354
3350
|
if (faceDetectorPreloading) return [2 /*return*/, new Promise(function (resolve) {
|
|
3355
|
-
setInterval(function () {
|
|
3356
|
-
if (!faceDetectorPreloading)
|
|
3351
|
+
var i = setInterval(function () {
|
|
3352
|
+
if (!faceDetectorPreloading) {
|
|
3353
|
+
clearInterval(i);
|
|
3354
|
+
resolve();
|
|
3355
|
+
}
|
|
3357
3356
|
}, 100);
|
|
3358
3357
|
})];
|
|
3359
3358
|
faceDetectorPreloading = true;
|
|
@@ -3416,33 +3415,32 @@ var documentTypeDisplayNames = {
|
|
|
3416
3415
|
passport: 'Passport',
|
|
3417
3416
|
none: 'None'
|
|
3418
3417
|
};
|
|
3419
|
-
var
|
|
3418
|
+
var detector = null;
|
|
3419
|
+
var detectorSettings = null;
|
|
3420
3420
|
function loadDocumentDetector() {
|
|
3421
3421
|
return __awaiter(this, arguments, void 0, function (modelAssetPath, scoreThreshold) {
|
|
3422
|
-
var
|
|
3422
|
+
var _a, _b;
|
|
3423
3423
|
if (modelAssetPath === void 0) {
|
|
3424
3424
|
modelAssetPath = defaultDocumentDetectorModelPath;
|
|
3425
3425
|
}
|
|
3426
3426
|
if (scoreThreshold === void 0) {
|
|
3427
3427
|
scoreThreshold = defaultDocumentDetectionScoreThreshold;
|
|
3428
3428
|
}
|
|
3429
|
-
return __generator(this, function (
|
|
3430
|
-
switch (
|
|
3429
|
+
return __generator(this, function (_c) {
|
|
3430
|
+
switch (_c.label) {
|
|
3431
3431
|
case 0:
|
|
3432
|
-
|
|
3433
|
-
|
|
3432
|
+
if (detector && (detectorSettings === null || detectorSettings === void 0 ? void 0 : detectorSettings.modelAssetPath) === modelAssetPath && (detectorSettings === null || detectorSettings === void 0 ? void 0 : detectorSettings.scoreThreshold) === scoreThreshold) return [2 /*return*/, detector];
|
|
3433
|
+
closeDocumentDetector();
|
|
3434
3434
|
return [4 /*yield*/, preloadDocumentDetectorDependencies()];
|
|
3435
3435
|
case 1:
|
|
3436
|
-
|
|
3436
|
+
_c.sent();
|
|
3437
3437
|
if (modelCapabilities.delegate === 'NONE') {
|
|
3438
3438
|
throw new Error('No available delegate for document detector.');
|
|
3439
3439
|
}
|
|
3440
|
-
_a =
|
|
3441
|
-
_b = id;
|
|
3442
|
-
_d = (_c = ObjectDetector).createFromOptions;
|
|
3440
|
+
_b = (_a = ObjectDetector).createFromOptions;
|
|
3443
3441
|
return [4 /*yield*/, FilesetResolver.forVisionTasks(visionTasksBasePath)];
|
|
3444
3442
|
case 2:
|
|
3445
|
-
return [4 /*yield*/,
|
|
3443
|
+
return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
|
|
3446
3444
|
baseOptions: {
|
|
3447
3445
|
modelAssetPath: modelAssetPath,
|
|
3448
3446
|
delegate: modelCapabilities.delegate
|
|
@@ -3452,23 +3450,20 @@ function loadDocumentDetector() {
|
|
|
3452
3450
|
runningMode: 'VIDEO'
|
|
3453
3451
|
}])];
|
|
3454
3452
|
case 3:
|
|
3455
|
-
|
|
3456
|
-
|
|
3453
|
+
detector = _c.sent();
|
|
3454
|
+
detectorSettings = {
|
|
3455
|
+
modelAssetPath: modelAssetPath,
|
|
3456
|
+
scoreThreshold: scoreThreshold
|
|
3457
|
+
};
|
|
3458
|
+
return [2 /*return*/, detector];
|
|
3457
3459
|
}
|
|
3458
3460
|
});
|
|
3459
3461
|
});
|
|
3460
3462
|
}
|
|
3461
|
-
function closeDocumentDetector(
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
if (scoreThreshold === void 0) {
|
|
3466
|
-
scoreThreshold = defaultDocumentDetectionScoreThreshold;
|
|
3467
|
-
}
|
|
3468
|
-
var id = "".concat(modelAssetPath, ":").concat(scoreThreshold);
|
|
3469
|
-
if (!detectors[id]) return;
|
|
3470
|
-
detectors[id].close();
|
|
3471
|
-
delete detectors[id];
|
|
3463
|
+
function closeDocumentDetector() {
|
|
3464
|
+
detector === null || detector === void 0 ? void 0 : detector.close();
|
|
3465
|
+
detector = null;
|
|
3466
|
+
detectorSettings = null;
|
|
3472
3467
|
}
|
|
3473
3468
|
function useLoadDocumentDetector(_a) {
|
|
3474
3469
|
var _b = _a.modelPath,
|
|
@@ -3478,7 +3473,6 @@ function useLoadDocumentDetector(_a) {
|
|
|
3478
3473
|
_d = _a.scoreThreshold,
|
|
3479
3474
|
scoreThreshold = _d === void 0 ? defaultDocumentDetectionScoreThreshold : _d,
|
|
3480
3475
|
onModelError = _a.onModelError;
|
|
3481
|
-
var detector = useRef(null);
|
|
3482
3476
|
var _e = useState(false),
|
|
3483
3477
|
ready = _e[0],
|
|
3484
3478
|
setReady = _e[1];
|
|
@@ -3504,7 +3498,6 @@ function useLoadDocumentDetector(_a) {
|
|
|
3504
3498
|
return __generator(this, function (_a) {
|
|
3505
3499
|
switch (_a.label) {
|
|
3506
3500
|
case 0:
|
|
3507
|
-
detector.current = model;
|
|
3508
3501
|
setModelDownloadProgress(100);
|
|
3509
3502
|
clearTimeout(modelLoadTimeout);
|
|
3510
3503
|
return [4 /*yield*/, waitForVideoReady(videoRef)];
|
|
@@ -3525,8 +3518,7 @@ function useLoadDocumentDetector(_a) {
|
|
|
3525
3518
|
});
|
|
3526
3519
|
return function () {
|
|
3527
3520
|
log('unloading document detection model');
|
|
3528
|
-
|
|
3529
|
-
closeDocumentDetector(modelPath, scoreThreshold);
|
|
3521
|
+
closeDocumentDetector();
|
|
3530
3522
|
clearTimeout(modelLoadTimeout);
|
|
3531
3523
|
document.removeEventListener('idmission.preloadProgress.documentDetection', handleDownloadProgress);
|
|
3532
3524
|
};
|
|
@@ -3535,17 +3527,17 @@ function useLoadDocumentDetector(_a) {
|
|
|
3535
3527
|
modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
|
|
3536
3528
|
}, [modelError, onModelError]);
|
|
3537
3529
|
return {
|
|
3538
|
-
detector: detector,
|
|
3539
3530
|
ready: ready,
|
|
3540
3531
|
modelDownloadProgress: modelDownloadProgress,
|
|
3541
3532
|
modelError: modelError,
|
|
3542
3533
|
setModelError: setModelError
|
|
3543
3534
|
};
|
|
3544
3535
|
}
|
|
3545
|
-
function makeDocumentDetectorPrediction(
|
|
3536
|
+
function makeDocumentDetectorPrediction(frame) {
|
|
3546
3537
|
return __awaiter(this, void 0, void 0, function () {
|
|
3547
3538
|
var startedAt, prediction, time, frameWidth, frameHeight;
|
|
3548
3539
|
return __generator(this, function (_a) {
|
|
3540
|
+
if (!detector) return [2 /*return*/, null];
|
|
3549
3541
|
startedAt = new Date();
|
|
3550
3542
|
// Detectors can throw errors, for example when using custom URLs that
|
|
3551
3543
|
// contain a model that doesn't provide the expected output.
|
|
@@ -3869,7 +3861,6 @@ function DocumentDetectionModelProvider(_a) {
|
|
|
3869
3861
|
scoreThreshold: documentDetectionModelScoreThreshold,
|
|
3870
3862
|
onModelError: onDocumentDetectionModelError
|
|
3871
3863
|
}),
|
|
3872
|
-
detector = _o.detector,
|
|
3873
3864
|
ready = _o.ready,
|
|
3874
3865
|
modelDownloadProgress = _o.modelDownloadProgress,
|
|
3875
3866
|
modelError = _o.modelError,
|
|
@@ -3881,7 +3872,7 @@ function DocumentDetectionModelProvider(_a) {
|
|
|
3881
3872
|
return __generator(this, function (_b) {
|
|
3882
3873
|
switch (_b.label) {
|
|
3883
3874
|
case 0:
|
|
3884
|
-
if (!videoLoaded || !cameraReady || !ready || !videoRef.current || !
|
|
3875
|
+
if (!videoLoaded || !cameraReady || !ready || !videoRef.current || !lastPredictionCanvas.current) return [2 /*return*/];
|
|
3885
3876
|
stopDetectionAtStart = stopDetection.current;
|
|
3886
3877
|
vw = videoRef.current.videoWidth;
|
|
3887
3878
|
vh = videoRef.current.videoHeight;
|
|
@@ -3891,7 +3882,7 @@ function DocumentDetectionModelProvider(_a) {
|
|
|
3891
3882
|
if (!(ctx && videoRef.current.readyState === 4)) return [3 /*break*/, 3];
|
|
3892
3883
|
if (stopDetectionAtStart !== stopDetection.current) return [2 /*return*/];
|
|
3893
3884
|
ctx.drawImage(videoRef.current, 0, 0, vw, vh);
|
|
3894
|
-
return [4 /*yield*/, makeDocumentDetectorPrediction(
|
|
3885
|
+
return [4 /*yield*/, makeDocumentDetectorPrediction(lastPredictionCanvas.current)];
|
|
3895
3886
|
case 1:
|
|
3896
3887
|
prediction = _b.sent();
|
|
3897
3888
|
if (!prediction) return [3 /*break*/, 3];
|
|
@@ -3913,7 +3904,7 @@ function DocumentDetectionModelProvider(_a) {
|
|
|
3913
3904
|
}
|
|
3914
3905
|
});
|
|
3915
3906
|
});
|
|
3916
|
-
}, [cameraReady, delayAfterStartMs,
|
|
3907
|
+
}, [cameraReady, delayAfterStartMs, documentDetectionBoundaries, documentDetectionThresholds, ready, videoLoaded, videoRef]), {
|
|
3917
3908
|
throttleMs: throttleMs,
|
|
3918
3909
|
autoStart: autoStart
|
|
3919
3910
|
}),
|
|
@@ -3990,16 +3981,16 @@ function FocusModelProvider(_a) {
|
|
|
3990
3981
|
modelLoadTimeoutMs: focusModelLoadTimeoutMs,
|
|
3991
3982
|
onModelError: onFocusModelError
|
|
3992
3983
|
}),
|
|
3993
|
-
model = _f.model,
|
|
3994
3984
|
ready = _f.ready,
|
|
3995
3985
|
modelDownloadProgress = _f.modelDownloadProgress,
|
|
3996
3986
|
modelError = _f.modelError;
|
|
3997
3987
|
var makeFocusPrediction = useCallback(function (imageData, box) {
|
|
3998
|
-
if (!
|
|
3999
|
-
var prediction = makeFocusModelPrediction(
|
|
3988
|
+
if (!ready) return null;
|
|
3989
|
+
var prediction = makeFocusModelPrediction(imageData, cropCanvas.current, rotateCanvas.current, box);
|
|
3990
|
+
if (!prediction) return null;
|
|
4000
3991
|
setLastFocusPredictionAt(prediction.predictionTime);
|
|
4001
3992
|
return prediction;
|
|
4002
|
-
}, [
|
|
3993
|
+
}, [ready]);
|
|
4003
3994
|
var value = useMemo(function () {
|
|
4004
3995
|
return {
|
|
4005
3996
|
focusModelReady: ready,
|
|
@@ -9222,18 +9213,17 @@ function SelfieGuidanceModelsProvider(_a) {
|
|
|
9222
9213
|
onModelError: onModelError,
|
|
9223
9214
|
modelLoadTimeoutMs: modelLoadTimeoutMs
|
|
9224
9215
|
}),
|
|
9225
|
-
detector = _f.detector,
|
|
9226
9216
|
ready = _f.ready,
|
|
9227
9217
|
modelDownloadProgress = _f.modelDownloadProgress,
|
|
9228
9218
|
modelError = _f.modelError;
|
|
9229
9219
|
var _g = useFrameLoop(useCallback(function () {
|
|
9230
9220
|
return __awaiter(_this, void 0, void 0, function () {
|
|
9231
|
-
var vw, vh, ctx,
|
|
9232
|
-
var _a;
|
|
9233
|
-
return __generator(this, function (
|
|
9234
|
-
switch (
|
|
9221
|
+
var vw, vh, ctx, prediction, processed, e_1;
|
|
9222
|
+
var _a, _b;
|
|
9223
|
+
return __generator(this, function (_c) {
|
|
9224
|
+
switch (_c.label) {
|
|
9235
9225
|
case 0:
|
|
9236
|
-
if (!videoLoaded || !cameraReady || !ready || modelError || !videoRef.current || !
|
|
9226
|
+
if (!videoLoaded || !cameraReady || !ready || modelError || !videoRef.current || !canvasRef.current) return [2 /*return*/];
|
|
9237
9227
|
vw = videoRef.current.videoWidth;
|
|
9238
9228
|
vh = videoRef.current.videoHeight;
|
|
9239
9229
|
ctx = canvasRef.current.getContext('2d');
|
|
@@ -9243,23 +9233,23 @@ function SelfieGuidanceModelsProvider(_a) {
|
|
|
9243
9233
|
ctx.translate(vw, 0);
|
|
9244
9234
|
ctx.scale(-1, 1);
|
|
9245
9235
|
ctx.drawImage(videoRef.current, 0, 0, vw, vh);
|
|
9246
|
-
|
|
9236
|
+
_c.label = 1;
|
|
9247
9237
|
case 1:
|
|
9248
|
-
|
|
9249
|
-
|
|
9238
|
+
_c.trys.push([1, 3,, 4]);
|
|
9239
|
+
prediction = makeFaceDetectorPrediction(canvasRef.current);
|
|
9250
9240
|
processed = processFaceDetectorPrediction({
|
|
9251
|
-
faces: faces,
|
|
9241
|
+
faces: (_a = prediction === null || prediction === void 0 ? void 0 : prediction.faces) !== null && _a !== void 0 ? _a : [],
|
|
9252
9242
|
videoWidth: vw,
|
|
9253
9243
|
videoHeight: vh,
|
|
9254
9244
|
requireVerticalFaceCentering: requireVerticalFaceCentering
|
|
9255
9245
|
});
|
|
9256
9246
|
setLastFaceDetectionAt(new Date().getTime());
|
|
9257
|
-
return [4 /*yield*/, (
|
|
9247
|
+
return [4 /*yield*/, (_b = onPredictionHandler.current) === null || _b === void 0 ? void 0 : _b.call(onPredictionHandler, processed)];
|
|
9258
9248
|
case 2:
|
|
9259
|
-
|
|
9249
|
+
_c.sent();
|
|
9260
9250
|
return [3 /*break*/, 4];
|
|
9261
9251
|
case 3:
|
|
9262
|
-
e_1 =
|
|
9252
|
+
e_1 = _c.sent();
|
|
9263
9253
|
error('caught face detection error', e_1);
|
|
9264
9254
|
return [3 /*break*/, 4];
|
|
9265
9255
|
case 4:
|
|
@@ -9267,7 +9257,7 @@ function SelfieGuidanceModelsProvider(_a) {
|
|
|
9267
9257
|
}
|
|
9268
9258
|
});
|
|
9269
9259
|
});
|
|
9270
|
-
}, [cameraReady,
|
|
9260
|
+
}, [cameraReady, modelError, ready, requireVerticalFaceCentering, videoLoaded, videoRef]), {
|
|
9271
9261
|
throttleMs: throttleMs,
|
|
9272
9262
|
autoStart: autoStart
|
|
9273
9263
|
}),
|