idmission-web-sdk 2.1.102 → 2.1.104

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.
@@ -234,7 +234,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
234
234
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
235
235
  };
236
236
 
237
- var webSdkVersion = '2.1.102';
237
+ var webSdkVersion = '2.1.104';
238
238
 
239
239
  function getPlatform() {
240
240
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -2754,15 +2754,6 @@ function waitForVideoReady(videoRef, checkEveryMs) {
2754
2754
  }, checkEveryMs);
2755
2755
  });
2756
2756
  }
2757
- function createPairs(arr, maxPairs) {
2758
- var pairs = [];
2759
- var len = arr.length - 1;
2760
- var end = Math.min(maxPairs , len);
2761
- for (var i = 0; i < end; i++) {
2762
- pairs.push([arr[i], arr[i + 1]]);
2763
- }
2764
- return pairs;
2765
- }
2766
2757
  function calculateIoU(boxA, boxB) {
2767
2758
  var xA = Math.max(boxA.xMin, boxB.xMin);
2768
2759
  var yA = Math.max(boxA.yMin, boxB.yMin);
@@ -5239,12 +5230,23 @@ function trackFramesNeeded$1(value, bufferLength) {
5239
5230
  if (framesNeededSamples$1.length > bufferLength) framesNeededSamples$1.length = bufferLength;
5240
5231
  }
5241
5232
  var lastNFaces = [];
5233
+ var lastNPairs$1 = [];
5242
5234
  function trackFace(face, framesNeeded) {
5243
5235
  if (framesNeeded === void 0) {
5244
5236
  framesNeeded = 12;
5245
5237
  }
5246
5238
  lastNFaces.unshift(face);
5247
5239
  if (lastNFaces.length > framesNeeded) lastNFaces.length = framesNeeded;
5240
+ if (lastNFaces.length > 1) {
5241
+ var lastFace = lastNFaces[1];
5242
+ var iou = calculateIoU(face.box, lastFace.box);
5243
+ lastNPairs$1.unshift({
5244
+ a: face,
5245
+ b: lastFace,
5246
+ iou: iou
5247
+ });
5248
+ if (lastNPairs$1.length > framesNeeded - 1) lastNPairs$1.length = framesNeeded - 1;
5249
+ }
5248
5250
  }
5249
5251
  function makeFaceDetectorPrediction(model, imageData) {
5250
5252
  var prediction = model.detectForVideo(imageData, performance.now());
@@ -5311,10 +5313,8 @@ function processFaceDetectorPrediction(_a) {
5311
5313
  if (faceInGuides) {
5312
5314
  var framesNeeded = Math.ceil(average(framesNeededSamples$1));
5313
5315
  trackFace(face, framesNeeded);
5314
- faceIsStable = lastNFaces.length >= framesNeeded && !createPairs(lastNFaces, 12).some(function (_a) {
5315
- var a = _a[0],
5316
- b = _a[1];
5317
- return calculateIoU(a.box, b.box) < stabilityThreshold;
5316
+ faceIsStable = lastNFaces.length >= framesNeeded && !lastNPairs$1.some(function (pair) {
5317
+ return pair.iou < stabilityThreshold;
5318
5318
  });
5319
5319
  }
5320
5320
  var faceReady = faceInGuides && faceIsStable;
@@ -5726,12 +5726,23 @@ function trackFramesNeeded(value, bufferLength) {
5726
5726
  if (framesNeededSamples.length > bufferLength) framesNeededSamples.length = bufferLength;
5727
5727
  }
5728
5728
  var lastNBoxes = [];
5729
+ var lastNPairs = [];
5729
5730
  function trackBox(box, framesNeeded) {
5730
5731
  if (framesNeeded === void 0) {
5731
5732
  framesNeeded = 12;
5732
5733
  }
5733
5734
  lastNBoxes.unshift(box);
5734
5735
  if (lastNBoxes.length > framesNeeded) lastNBoxes.length = framesNeeded;
5736
+ if (lastNBoxes.length > 1) {
5737
+ var lastBox = lastNBoxes[1];
5738
+ var iou = calculateIoU(box, lastBox);
5739
+ lastNPairs.unshift({
5740
+ a: box,
5741
+ b: lastBox,
5742
+ iou: iou
5743
+ });
5744
+ if (lastNPairs.length > framesNeeded - 1) lastNPairs.length = framesNeeded - 1;
5745
+ }
5735
5746
  }
5736
5747
  var defaultDocumentDetectionBoundaries = {
5737
5748
  top: 20,
@@ -5748,6 +5759,11 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
5748
5759
  frameWidth = prediction.frameWidth,
5749
5760
  frameHeight = prediction.frameHeight,
5750
5761
  time = prediction.time;
5762
+ var boundaryTop = (_a = boundaries.top) !== null && _a !== void 0 ? _a : 20;
5763
+ var boundaryLeft = (_b = boundaries.left) !== null && _b !== void 0 ? _b : 20;
5764
+ var boundaryRight = (_c = boundaries.right) !== null && _c !== void 0 ? _c : 20;
5765
+ var boundaryBottom = (_d = boundaries.bottom) !== null && _d !== void 0 ? _d : 20;
5766
+ var frameWidth80Pct = frameWidth * 0.8;
5751
5767
  var detectedObjects = applyNonMaxSuppression(detections.map(function (d) {
5752
5768
  var _a;
5753
5769
  var category = (_a = d.categories) === null || _a === void 0 ? void 0 : _a[0];
@@ -5756,7 +5772,21 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
5756
5772
  score: category === null || category === void 0 ? void 0 : category.score,
5757
5773
  box: convertBoundingBox(d.boundingBox)
5758
5774
  };
5759
- }));
5775
+ }), function (obj) {
5776
+ var _a = obj.box,
5777
+ xMin = _a.xMin,
5778
+ yMin = _a.yMin,
5779
+ width = _a.width,
5780
+ height = _a.height;
5781
+ return yMin > boundaryTop &&
5782
+ // Is it valid top edge of ID detected?
5783
+ yMin + height + boundaryBottom < frameHeight && (
5784
+ // Is it valid bottom edge less than max video height
5785
+ xMin > boundaryLeft || xMin + width > frameWidth80Pct) &&
5786
+ // If either the left side visible or if not, right edge of ID should be more than 80% of width.
5787
+ xMin + width + boundaryRight < frameWidth // Valid right edge if it's less than video width.
5788
+ ;
5789
+ });
5760
5790
  var allZero = detections.length > 0 && !detections.some(function (_a) {
5761
5791
  var boundingBox = _a.boundingBox;
5762
5792
  return Object.values(boundingBox !== null && boundingBox !== void 0 ? boundingBox : {}).some(function (n) {
@@ -5772,15 +5802,15 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
5772
5802
  var bestPassportPage = detectedObjects.find(function (obj) {
5773
5803
  return obj.label === 'Passport page';
5774
5804
  });
5775
- var idCardFrontDetectionScore = (_a = bestIdCardFront === null || bestIdCardFront === void 0 ? void 0 : bestIdCardFront.score) !== null && _a !== void 0 ? _a : 0;
5776
- var idCardBackDetectionScore = (_b = bestIdCardBack === null || bestIdCardBack === void 0 ? void 0 : bestIdCardBack.score) !== null && _b !== void 0 ? _b : 0;
5777
- var passportDetectionScore = (_c = bestPassportPage === null || bestPassportPage === void 0 ? void 0 : bestPassportPage.score) !== null && _c !== void 0 ? _c : 0;
5778
- var idCardFrontDetectionThresholdMet = idCardFrontDetectionScore >= ((_d = thresholds.idCardFront) !== null && _d !== void 0 ? _d : 0);
5779
- var idCardBackDetectionThresholdMet = idCardBackDetectionScore >= ((_e = thresholds.idCardBack) !== null && _e !== void 0 ? _e : 0);
5780
- var passportDetectionThresholdMet = passportDetectionScore >= ((_f = thresholds.passport) !== null && _f !== void 0 ? _f : 0);
5805
+ var idCardFrontDetectionScore = (_e = bestIdCardFront === null || bestIdCardFront === void 0 ? void 0 : bestIdCardFront.score) !== null && _e !== void 0 ? _e : 0;
5806
+ var idCardBackDetectionScore = (_f = bestIdCardBack === null || bestIdCardBack === void 0 ? void 0 : bestIdCardBack.score) !== null && _f !== void 0 ? _f : 0;
5807
+ var passportDetectionScore = (_g = bestPassportPage === null || bestPassportPage === void 0 ? void 0 : bestPassportPage.score) !== null && _g !== void 0 ? _g : 0;
5808
+ var idCardFrontDetectionThresholdMet = idCardFrontDetectionScore >= ((_h = thresholds.idCardFront) !== null && _h !== void 0 ? _h : 0);
5809
+ var idCardBackDetectionThresholdMet = idCardBackDetectionScore >= ((_j = thresholds.idCardBack) !== null && _j !== void 0 ? _j : 0);
5810
+ var passportDetectionThresholdMet = passportDetectionScore >= ((_k = thresholds.passport) !== null && _k !== void 0 ? _k : 0);
5781
5811
  var bestDocument = passportDetectionThresholdMet ? bestPassportPage : idCardBackDetectionThresholdMet ? bestIdCardBack : bestIdCardFront;
5782
5812
  var detectionThreshold = passportDetectionThresholdMet ? thresholds.passport : idCardBackDetectionThresholdMet ? thresholds.idCardBack : thresholds.idCardFront;
5783
- var detectionScore = (_g = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _g !== void 0 ? _g : 0;
5813
+ var detectionScore = (_l = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _l !== void 0 ? _l : 0;
5784
5814
  var detectionThresholdMet = detectionScore >= (detectionThreshold !== null && detectionThreshold !== void 0 ? detectionThreshold : 0);
5785
5815
  var detectedDocumentType = 'none';
5786
5816
  if (passportDetectionThresholdMet) {
@@ -5790,43 +5820,23 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
5790
5820
  } else if (detectionThresholdMet) {
5791
5821
  detectedDocumentType = 'idCardFront';
5792
5822
  }
5793
- var documentInBounds = false;
5794
- if (bestDocument) {
5795
- var boundaryTop = (_h = boundaries.top) !== null && _h !== void 0 ? _h : 20;
5796
- var boundaryLeft = (_j = boundaries.left) !== null && _j !== void 0 ? _j : 20;
5797
- var boundaryRight = (_k = boundaries.right) !== null && _k !== void 0 ? _k : 20;
5798
- var boundaryBottom = (_l = boundaries.bottom) !== null && _l !== void 0 ? _l : 20;
5799
- var _o = bestDocument.box,
5800
- xMin = _o.xMin,
5801
- yMin = _o.yMin,
5802
- width = _o.width,
5803
- height = _o.height;
5804
- documentInBounds = yMin > boundaryTop &&
5805
- // Is it valid top edge of ID detected?
5806
- yMin + height + boundaryBottom < frameHeight && (
5807
- // Is it valid bottom edge less than max video height
5808
- xMin > boundaryLeft || xMin < boundaryLeft && xMin + width > frameWidth * 0.8) &&
5809
- // If either the left side visible or if not, right edge of ID should be more than 80% of width.
5810
- xMin + width + boundaryRight < frameWidth; // Valid right edge if it's less than video width.
5811
- }
5823
+ var documentInBounds = !!bestDocument;
5812
5824
  if (lastDetectionTime > 0) {
5813
5825
  trackFramesNeeded(1000 / lastDetectionTime);
5814
5826
  }
5815
5827
  var documentIsStable = false;
5816
5828
  var documentTooClose = false;
5817
5829
  if (bestDocument) {
5818
- var _p = [bestDocument.box.width / frameWidth, bestDocument.box.height / frameHeight],
5819
- docWidth = _p[0],
5820
- docHeight = _p[1];
5830
+ var _o = [bestDocument.box.width / frameWidth, bestDocument.box.height / frameHeight],
5831
+ docWidth = _o[0],
5832
+ docHeight = _o[1];
5821
5833
  documentTooClose = docWidth > 0.85 || docHeight > 0.85;
5822
5834
  if (detectionThresholdMet && documentInBounds && !documentTooClose) {
5823
5835
  var threshold_1 = (_m = thresholds.stability) !== null && _m !== void 0 ? _m : defaultDocumentDetectionThresholds.stability;
5824
5836
  var framesNeeded = Math.ceil(average(framesNeededSamples));
5825
5837
  trackBox(bestDocument.box, framesNeeded);
5826
- documentIsStable = lastNBoxes.length >= framesNeeded && !createPairs(lastNBoxes, 12).some(function (_a) {
5827
- var a = _a[0],
5828
- b = _a[1];
5829
- return calculateIoU(a, b) < threshold_1;
5838
+ documentIsStable = lastNBoxes.length >= framesNeeded && !lastNPairs.some(function (pair) {
5839
+ return pair.iou < threshold_1;
5830
5840
  });
5831
5841
  }
5832
5842
  }
@@ -5851,12 +5861,12 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
5851
5861
  allZero: allZero
5852
5862
  };
5853
5863
  }
5854
- function applyNonMaxSuppression(detectedObjects) {
5864
+ function applyNonMaxSuppression(detectedObjects, isGoodBox) {
5855
5865
  var maxes = {};
5856
5866
  detectedObjects.forEach(function (obj, i) {
5857
5867
  if (obj) {
5858
5868
  if (!maxes[obj.label]) maxes[obj.label] = [0, -1];
5859
- if (obj.score > maxes[obj.label][0]) maxes[obj.label] = [obj.score, i];
5869
+ if (obj.score > maxes[obj.label][0] && (isGoodBox === null || isGoodBox === void 0 ? void 0 : isGoodBox(obj))) maxes[obj.label] = [obj.score, i];
5860
5870
  }
5861
5871
  });
5862
5872
  return Object.keys(maxes).map(function (label) {
@@ -6286,7 +6296,7 @@ function IdCaptureModelsProviderInner(_a) {
6286
6296
  stopDetectionAtStart = stopDetection.current;
6287
6297
  focusPredictionTime = 0, focusScore = 0, focusThresholdMet = false;
6288
6298
  isRequiredDocumentType = requiredDocumentType === 'none' || prediction.detectedDocumentType === requiredDocumentType || ((_a = requiredDocumentType.includes) === null || _a === void 0 ? void 0 : _a.call(requiredDocumentType, prediction.detectedDocumentType));
6289
- if (isRequiredDocumentType && prediction.detectedDocumentType !== 'none' && prediction.detectionThresholdMet && prediction.documentInBounds && !prediction.documentTooClose) {
6299
+ if (isRequiredDocumentType && prediction.detectedDocumentType !== 'none' && prediction.detectionThresholdMet && prediction.documentInBounds && !prediction.documentTooClose && prediction.documentIsStable) {
6290
6300
  focusPrediction = makeFocusPrediction(lastPredictionCanvas.current, (_b = prediction.bestDocument) === null || _b === void 0 ? void 0 : _b.box);
6291
6301
  if (focusPrediction) {
6292
6302
  focusScore = focusPrediction.score;