@ekyc_qoobiss/qbs-ect-cmp 1.10.11 → 1.10.13

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.
@@ -56,7 +56,7 @@ export class IdentificationComponent {
56
56
  this.apiErrorEmitter(e);
57
57
  }
58
58
  }
59
- apiErrorEmitter(data) {
59
+ async apiErrorEmitter(data) {
60
60
  if (data.message) {
61
61
  this.errorMessage = data.message;
62
62
  }
@@ -69,7 +69,7 @@ export class IdentificationComponent {
69
69
  else {
70
70
  this.errorMessage = data;
71
71
  }
72
- this.apiCall.AddLog(data);
72
+ await this.apiCall.AddLog(data);
73
73
  Events.flowError(data);
74
74
  store.flowStatus = FlowStatus.ERROREND;
75
75
  }
@@ -94,10 +94,10 @@ export class ApiCall {
94
94
  let resp = await this.post(this.urls.SendLink, JSON.stringify(data));
95
95
  return resp.sent;
96
96
  }
97
- AddLog(error) {
97
+ async AddLog(error) {
98
98
  try {
99
99
  let data = { requestId: store.requestId, action: store.flowStatus, message: JSON.stringify(error !== null && error !== void 0 ? error : 'no error data') };
100
- this.post(this.urls.AddLog, JSON.stringify(data));
100
+ await this.post(this.urls.AddLog, JSON.stringify(data));
101
101
  }
102
102
  catch (_a) { }
103
103
  }
@@ -1,5 +1,7 @@
1
1
  import ml5 from 'ml5';
2
2
  import store from './store';
3
+ // @ts-ignore
4
+ import preload from '../assets/ml5-preload.png';
3
5
  export class ML5 {
4
6
  static getInstance() {
5
7
  if (!ML5.instance) {
@@ -13,10 +15,21 @@ export class ML5 {
13
15
  async init() {
14
16
  return new Promise(async (resolve) => {
15
17
  const modelPath = store.hasIdBack ? 'https://ekyc.blob.core.windows.net/$web/md/model.json' : 'https://ekyc.blob.core.windows.net/$web/model.json';
16
- this.classifier = await ml5.imageClassifier(modelPath);
17
- this.faceapi = await ml5.faceApi({ withLandmarks: true, withDescriptors: false });
18
+ this.classifier = await ml5.imageClassifier(modelPath, this.loaded);
19
+ this.faceapi = await ml5.faceApi({ withLandmarks: true, withDescriptors: false }, this.loaded);
20
+ //warmup
21
+ const img = new Image();
22
+ img.src = preload;
23
+ this.classifier.classify(img, this.gotResults);
24
+ this.faceapi.detect(img, this.gotResults);
18
25
  resolve();
19
- console.log('ML5 LOADED!!!');
20
26
  });
21
27
  }
28
+ loaded() {
29
+ console.log('ML5 LOADED!!!');
30
+ }
31
+ gotResults(error, results) {
32
+ console.log(error);
33
+ console.log(results);
34
+ }
22
35
  }
@@ -130,7 +130,7 @@ export class Stream {
130
130
  this.mediaRecorder.ondataavailable = event => {
131
131
  this.recordedChunks.push(event.data);
132
132
  };
133
- this.mediaRecorder.onstop = async () => {
133
+ this.mediaRecorder.onstop = (_e) => {
134
134
  this.saveVideoRecording(this.recordedChunks, options.mimeType);
135
135
  this.recordedChunks = [];
136
136
  };
@@ -1,5 +1,5 @@
1
1
  import { ML5 } from '../../helpers/ML5';
2
- import { getVideoRatio } from '../../helpers/canvas';
2
+ // import { getVideoRatio } from '../../helpers/canvas';
3
3
  import { FacePose } from '../FaceML5Detector/FacePose';
4
4
  import { FaceLandmarks } from '../FaceML5Detector/FacePose';
5
5
  // @ts-ignore
@@ -17,7 +17,6 @@ export class FaceML5Detector {
17
17
  constructor(stream, isMobile) {
18
18
  this.MAX_DETECTION = 1000 * 30;
19
19
  this.initTime = null;
20
- this.videoRatio = 1;
21
20
  this.validFaceFound = false;
22
21
  this.start = null;
23
22
  this.frontFace = null;
@@ -26,13 +25,13 @@ export class FaceML5Detector {
26
25
  this.validFacePose = false;
27
26
  this.validFaceFoundAgain = false;
28
27
  this.MAX_NUMBER_FACES = 1;
29
- this.MIN_FACE_SCORE = 0.65;
30
- this.MIN_FACE_SIZE_FOR_MOBILE = 200;
31
- this.MIN_FACE_SIZE_FOR_DESKTOP = 350;
32
- this.MIN_OCCUPIED_SPACE_FOR_DESKTOP = 15;
33
- this.MIN_OCCUPIED_SPACE_FOR_MOBILE = 15;
34
- this.X_OFFSET_FROM_FRAME = 5;
35
- this.Y_OFFSET_FROM_FRAME = 5;
28
+ this.MIN_FACE_SCORE = 0.75;
29
+ // private readonly MIN_FACE_SIZE_FOR_MOBILE = 200;
30
+ // private readonly MIN_FACE_SIZE_FOR_DESKTOP = 350;
31
+ this.MIN_OCCUPIED_SPACE_FOR_DESKTOP = 20;
32
+ this.MIN_OCCUPIED_SPACE_FOR_MOBILE = 30;
33
+ this.X_OFFSET_FROM_FRAME = 2;
34
+ this.Y_OFFSET_FROM_FRAME = 2;
36
35
  this.stream = stream;
37
36
  this.ml5 = ML5.getInstance();
38
37
  this.isMobile = isMobile;
@@ -47,7 +46,7 @@ export class FaceML5Detector {
47
46
  this.continue = true;
48
47
  this.width = this.videoElement.videoWidth;
49
48
  this.height = this.videoElement.videoHeight;
50
- this.videoRatio = getVideoRatio(this.videoElement);
49
+ // this.videoRatio = getVideoRatio(this.videoElement);
51
50
  this.drawFrame('white');
52
51
  this.delay(2000).then(() => this.detectFaces());
53
52
  }
@@ -82,12 +81,12 @@ export class FaceML5Detector {
82
81
  if (!this.validFaceFound) {
83
82
  this.validFaceFound = true;
84
83
  this.stream.autoCapturing();
85
- this.frontFace = new FaceLandmarks(results[0], this.width, this.height);
84
+ // this.frontFace = new FaceLandmarks(results[0], this.width, this.height);
86
85
  await this.drawFrame('green');
87
86
  this.requestedFacePose = this.stream.requestFacePose();
88
87
  await this.delay(GlobalValues.VideoLenght);
89
88
  }
90
- if (this.validFaceFound && !this.validFaceFoundAgain) {
89
+ else if (this.validFaceFound && !this.validFaceFoundAgain) {
91
90
  await this.checkFacePose(results);
92
91
  }
93
92
  }
@@ -132,28 +131,36 @@ export class FaceML5Detector {
132
131
  }
133
132
  checkFaceSize(result) {
134
133
  const faceBox = result[0].detection.box;
135
- const { width, height, area } = faceBox;
134
+ const { area } = faceBox;
135
+ // const { width, height, area } = faceBox;
136
136
  const { imageHeight, imageWidth } = result[0].detection;
137
137
  const occupiedSize = 100 / ((imageHeight * imageWidth) / area);
138
- const minSide = Math.min(width / this.videoRatio, height / this.videoRatio);
139
- return (minSide > (this.isMobile ? this.MIN_FACE_SIZE_FOR_MOBILE : this.MIN_FACE_SIZE_FOR_DESKTOP) &&
140
- occupiedSize > (this.isMobile ? this.MIN_OCCUPIED_SPACE_FOR_MOBILE : this.MIN_OCCUPIED_SPACE_FOR_DESKTOP));
138
+ // const minSide = Math.min(width / this.videoRatio, height / this.videoRatio);
139
+ return (
140
+ // minSide > (this.isMobile ? this.MIN_FACE_SIZE_FOR_MOBILE : this.MIN_FACE_SIZE_FOR_DESKTOP) &&
141
+ occupiedSize > (this.isMobile ? this.MIN_OCCUPIED_SPACE_FOR_MOBILE : this.MIN_OCCUPIED_SPACE_FOR_DESKTOP));
141
142
  }
142
143
  checkFaceIndent(result) {
143
144
  const faceBox = result[0].detection.box;
144
- const { imageHeight, imageWidth } = result[0].detection;
145
145
  const { top, left, bottom, right } = faceBox;
146
- const topIndent = top;
147
- const leftIndent = left;
148
- const rightIndent = imageWidth - right;
149
- const bottomIndent = imageHeight - bottom;
150
- return !(topIndent < this.Y_OFFSET_FROM_FRAME || leftIndent < this.X_OFFSET_FROM_FRAME || rightIndent < this.X_OFFSET_FROM_FRAME || bottomIndent < this.Y_OFFSET_FROM_FRAME);
146
+ const { imageHeight, imageWidth } = result[0].detection;
147
+ const topIndent = top * 100 / imageHeight;
148
+ const leftIndent = left * 100 / imageWidth;
149
+ const rightIndent = (imageWidth - right) * 100 / imageWidth;
150
+ const bottomIndent = (imageHeight - bottom) * 100 / imageHeight;
151
+ return !(topIndent < this.Y_OFFSET_FROM_FRAME ||
152
+ leftIndent < this.X_OFFSET_FROM_FRAME ||
153
+ rightIndent < this.X_OFFSET_FROM_FRAME ||
154
+ bottomIndent < this.Y_OFFSET_FROM_FRAME);
151
155
  }
152
156
  async checkFacePose(results) {
153
157
  let face = new FaceLandmarks(results[0], this.width, this.height);
154
158
  // this.drawLandmarks(results);
155
159
  // this.drawPoints(face);
156
- if (this.presentedFacePose == null) {
160
+ if (this.frontFace == null) {
161
+ this.frontFace = face;
162
+ }
163
+ else if (this.frontFace != null && this.presentedFacePose == null) {
157
164
  let ff = this.frontFace;
158
165
  if (face.nose.y < ff.nose.y - (ff.eyesDistance() * 0.4))
159
166
  this.presentedFacePose = FacePose.LookUp;