@utamuratov/ngx-face-id 0.0.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/LICENSE +21 -0
- package/README.md +63 -0
- package/fesm2022/utamuratov-ngx-face-id.mjs +263 -0
- package/fesm2022/utamuratov-ngx-face-id.mjs.map +1 -0
- package/package.json +33 -0
- package/types/utamuratov-ngx-face-id.d.ts +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2026] [Odilbek Utamuratov]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# NgxFaceId
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.1.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build ngx-face-id
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/ngx-face-id
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { signal, computed, Injectable, output, ViewChild, Component } from '@angular/core';
|
|
3
|
+
import * as faceapi from 'face-api.js';
|
|
4
|
+
|
|
5
|
+
class LivenessService {
|
|
6
|
+
step = signal('BLINK', ...(ngDevMode ? [{ debugName: "step" }] : []));
|
|
7
|
+
faceInsideStatus = signal('OUTSIDE_OVAL', ...(ngDevMode ? [{ debugName: "faceInsideStatus" }] : []));
|
|
8
|
+
currentStep = computed(() => this.step(), ...(ngDevMode ? [{ debugName: "currentStep" }] : []));
|
|
9
|
+
currentFaceInsideStatus = computed(() => this.faceInsideStatus(), ...(ngDevMode ? [{ debugName: "currentFaceInsideStatus" }] : []));
|
|
10
|
+
prevBlinkAvg = 0;
|
|
11
|
+
blinkCount = 0;
|
|
12
|
+
prevNoseX;
|
|
13
|
+
holdStart;
|
|
14
|
+
async loadModels() {
|
|
15
|
+
const MODEL_URL = '/models';
|
|
16
|
+
await Promise.all([
|
|
17
|
+
faceapi.nets.tinyFaceDetector.loadFromUri(MODEL_URL),
|
|
18
|
+
faceapi.nets.faceLandmark68Net.loadFromUri(MODEL_URL),
|
|
19
|
+
faceapi.nets.faceRecognitionNet.loadFromUri(MODEL_URL),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
reset() {
|
|
23
|
+
this.faceInsideStatus.set('OUTSIDE_OVAL');
|
|
24
|
+
this.step.set('BLINK');
|
|
25
|
+
this.blinkCount = 0;
|
|
26
|
+
this.prevBlinkAvg = 0;
|
|
27
|
+
this.prevNoseX = undefined;
|
|
28
|
+
this.holdStart = undefined;
|
|
29
|
+
}
|
|
30
|
+
// ---------- HELPERS ----------
|
|
31
|
+
isFaceInsideOval(box, video) {
|
|
32
|
+
const cx = video.videoWidth / 2;
|
|
33
|
+
const cy = video.videoHeight / 2;
|
|
34
|
+
// ✅ CSS: width: 50% → radius = 25%
|
|
35
|
+
const rx = video.videoWidth * 0.25;
|
|
36
|
+
const ry = rx * (6 / 5); // aspect-ratio: 5/6
|
|
37
|
+
// 1️⃣ Yuzning 4 ta chekkasi oval ichida bo'lishi kerak
|
|
38
|
+
const points = [
|
|
39
|
+
{ x: box.x, y: box.y + box.height / 2 }, // chap
|
|
40
|
+
{ x: box.x + box.width, y: box.y + box.height / 2 }, // o'ng
|
|
41
|
+
{ x: box.x + box.width / 2, y: box.y }, // tepa
|
|
42
|
+
{ x: box.x + box.width / 2, y: box.y + box.height }, // past
|
|
43
|
+
];
|
|
44
|
+
const inside = points.every((p) => {
|
|
45
|
+
const v = Math.pow(p.x - cx, 2) / Math.pow(rx, 2) + Math.pow(p.y - cy, 2) / Math.pow(ry, 2);
|
|
46
|
+
return v <= 1;
|
|
47
|
+
});
|
|
48
|
+
if (!inside) {
|
|
49
|
+
this.faceInsideStatus.set('OUTSIDE_OVAL');
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// 2️⃣ Yuz ovalni yaxshi to'ldirishi kerak (70-90%)
|
|
53
|
+
const faceArea = box.width * box.height;
|
|
54
|
+
const ovalArea = Math.PI * rx * ry;
|
|
55
|
+
const fillRatio = faceArea / ovalArea;
|
|
56
|
+
// Juda uzoq
|
|
57
|
+
if (fillRatio < 0.4) {
|
|
58
|
+
this.faceInsideStatus.set('COME_CLOSE');
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// Juda yaqin
|
|
62
|
+
if (fillRatio > 0.59) {
|
|
63
|
+
this.faceInsideStatus.set('VERY_CLOSE');
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
this.faceInsideStatus.set('VALID');
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
dist(a, b) {
|
|
70
|
+
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
71
|
+
}
|
|
72
|
+
eyeEAR(eye) {
|
|
73
|
+
return ((this.dist(eye[1], eye[5]) + this.dist(eye[2], eye[4])) / (2 * this.dist(eye[0], eye[3])));
|
|
74
|
+
}
|
|
75
|
+
isBlink(lm) {
|
|
76
|
+
const left = this.eyeEAR(lm.getLeftEye());
|
|
77
|
+
const right = this.eyeEAR(lm.getRightEye());
|
|
78
|
+
const avg = (left + right) / 2;
|
|
79
|
+
if (this.prevBlinkAvg === 0 || Math.abs(avg - this.prevBlinkAvg) < 0.01) {
|
|
80
|
+
this.prevBlinkAvg = avg;
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
this.prevBlinkAvg = avg;
|
|
84
|
+
this.blinkCount++;
|
|
85
|
+
return this.blinkCount > 2;
|
|
86
|
+
}
|
|
87
|
+
isMouthOpen(lm) {
|
|
88
|
+
const mouth = lm.getMouth();
|
|
89
|
+
return this.dist(mouth[13], mouth[19]) / this.dist(mouth[0], mouth[6]) > 0.4;
|
|
90
|
+
}
|
|
91
|
+
isHeadMoved(lm) {
|
|
92
|
+
const nose = lm.getNose()[3];
|
|
93
|
+
if (!this.prevNoseX) {
|
|
94
|
+
this.prevNoseX = nose.x;
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
const moved = Math.abs(nose.x - this.prevNoseX) > 30;
|
|
98
|
+
this.prevNoseX = nose.x;
|
|
99
|
+
return moved;
|
|
100
|
+
}
|
|
101
|
+
// ---------- MAIN CHECK ----------
|
|
102
|
+
async process(video) {
|
|
103
|
+
const result = await faceapi
|
|
104
|
+
.detectSingleFace(video, new faceapi.TinyFaceDetectorOptions())
|
|
105
|
+
.withFaceLandmarks();
|
|
106
|
+
if (!result) {
|
|
107
|
+
this.faceInsideStatus.set('NO_FACE');
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
// 👇 OVAL CHECK
|
|
111
|
+
const insideOval = this.isFaceInsideOval(result.detection.box, video);
|
|
112
|
+
if (!insideOval) {
|
|
113
|
+
if (this.step() === 'HOLD') {
|
|
114
|
+
this.holdStart = Date.now();
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const lm = result.landmarks;
|
|
119
|
+
if (this.step() === 'BLINK' && this.isBlink(lm)) {
|
|
120
|
+
this.step.set('MOUTH');
|
|
121
|
+
}
|
|
122
|
+
else if (this.step() === 'MOUTH' && this.isMouthOpen(lm)) {
|
|
123
|
+
this.step.set('HEAD');
|
|
124
|
+
}
|
|
125
|
+
else if (this.step() === 'HEAD' && this.isHeadMoved(lm)) {
|
|
126
|
+
this.step.set('HOLD');
|
|
127
|
+
this.holdStart = Date.now();
|
|
128
|
+
}
|
|
129
|
+
else if (this.step() === 'HOLD') {
|
|
130
|
+
if (!this.holdStart)
|
|
131
|
+
this.holdStart = Date.now();
|
|
132
|
+
if (Date.now() - this.holdStart > 3000) {
|
|
133
|
+
this.step.set('DONE');
|
|
134
|
+
return true; // 📸 CAPTURE SIGNAL
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: LivenessService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
140
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: LivenessService, providedIn: 'root' });
|
|
141
|
+
}
|
|
142
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: LivenessService, decorators: [{
|
|
143
|
+
type: Injectable,
|
|
144
|
+
args: [{ providedIn: 'root' }]
|
|
145
|
+
}] });
|
|
146
|
+
|
|
147
|
+
class NgxFaceLiveness {
|
|
148
|
+
liveness;
|
|
149
|
+
videoRef;
|
|
150
|
+
intervalId;
|
|
151
|
+
capturedImage = output();
|
|
152
|
+
constructor(liveness) {
|
|
153
|
+
this.liveness = liveness;
|
|
154
|
+
}
|
|
155
|
+
async ngOnInit() {
|
|
156
|
+
await this.liveness.loadModels();
|
|
157
|
+
await this.start();
|
|
158
|
+
}
|
|
159
|
+
currentStep = computed(() => this.liveness.currentStep(), ...(ngDevMode ? [{ debugName: "currentStep" }] : []));
|
|
160
|
+
currentFaceInsideStatus = computed(() => this.liveness.currentFaceInsideStatus(), ...(ngDevMode ? [{ debugName: "currentFaceInsideStatus" }] : []));
|
|
161
|
+
isNotValidOval = computed(() => this.currentFaceInsideStatus() === 'OUTSIDE_OVAL' ||
|
|
162
|
+
this.currentFaceInsideStatus() === 'NO_FACE', ...(ngDevMode ? [{ debugName: "isNotValidOval" }] : []));
|
|
163
|
+
stepText = computed(() => {
|
|
164
|
+
const currentFaceStatus = this.currentFaceInsideStatus();
|
|
165
|
+
if (currentFaceStatus === 'NO_FACE') {
|
|
166
|
+
return '❌ Yuz aniqlanmadi, iltimos, kameraga qarang';
|
|
167
|
+
}
|
|
168
|
+
if (currentFaceStatus === 'OUTSIDE_OVAL') {
|
|
169
|
+
return '📐 Iltimos, yuzingizni oval ichiga joylashtiring';
|
|
170
|
+
}
|
|
171
|
+
if (currentFaceStatus === 'COME_CLOSE') {
|
|
172
|
+
return '🔍 Iltimos, kameraga yaqinroq turing';
|
|
173
|
+
}
|
|
174
|
+
if (currentFaceStatus === 'VERY_CLOSE') {
|
|
175
|
+
return '📷 Juda yaqin, kamerani orqaroq oling';
|
|
176
|
+
}
|
|
177
|
+
switch (this.currentStep()) {
|
|
178
|
+
case 'BLINK':
|
|
179
|
+
return '👁 Ko‘zingizni yumib oching(kamida 2 marta)';
|
|
180
|
+
case 'MOUTH':
|
|
181
|
+
return '🙂 Og‘zingizni ochib yuming (kamida yarim ochish kerak)';
|
|
182
|
+
case 'HEAD':
|
|
183
|
+
return '↔️ Boshni chapga yoki o‘ngga burang';
|
|
184
|
+
case 'HOLD':
|
|
185
|
+
return '✋ Barqaror turing (2 soniya)';
|
|
186
|
+
default:
|
|
187
|
+
return '✅ Tayyor!';
|
|
188
|
+
}
|
|
189
|
+
}, ...(ngDevMode ? [{ debugName: "stepText" }] : []));
|
|
190
|
+
async start() {
|
|
191
|
+
this.liveness.reset();
|
|
192
|
+
await this.openCamera();
|
|
193
|
+
this.intervalId = setInterval(async () => {
|
|
194
|
+
const done = await this.liveness.process(this.videoRef.nativeElement);
|
|
195
|
+
if (done) {
|
|
196
|
+
clearInterval(this.intervalId);
|
|
197
|
+
const blob = await this.capture();
|
|
198
|
+
this.sendToBackend(blob);
|
|
199
|
+
}
|
|
200
|
+
}, 300);
|
|
201
|
+
}
|
|
202
|
+
async openCamera() {
|
|
203
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
204
|
+
video: { facingMode: 'user' },
|
|
205
|
+
});
|
|
206
|
+
this.videoRef.nativeElement.srcObject = stream;
|
|
207
|
+
}
|
|
208
|
+
async capture() {
|
|
209
|
+
const video = this.videoRef.nativeElement;
|
|
210
|
+
const canvas = document.createElement('canvas');
|
|
211
|
+
canvas.width = video.videoWidth;
|
|
212
|
+
canvas.height = video.videoHeight;
|
|
213
|
+
canvas.getContext('2d').drawImage(video, 0, 0);
|
|
214
|
+
return new Promise((res) => canvas.toBlob((b) => res(b), 'image/jpeg', 0.9));
|
|
215
|
+
}
|
|
216
|
+
sendToBackend(blob) {
|
|
217
|
+
this.capturedImage.emit(blob);
|
|
218
|
+
console.log(blob);
|
|
219
|
+
// const fd = new FormData();
|
|
220
|
+
// fd.append('file', blob, 'face.jpg');
|
|
221
|
+
// this.http.post('/api/face/verify', fd).subscribe();
|
|
222
|
+
}
|
|
223
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: NgxFaceLiveness, deps: [{ token: LivenessService }], target: i0.ɵɵFactoryTarget.Component });
|
|
224
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.1.2", type: NgxFaceLiveness, isStandalone: true, selector: "ngx-face-liveness", outputs: { capturedImage: "capturedImage" }, viewQueries: [{ propertyName: "videoRef", first: true, predicate: ["video"], descendants: true }], ngImport: i0, template: `
|
|
225
|
+
<div class="camera-wrapper">
|
|
226
|
+
<video #video autoplay muted playsinline class="camera-video"></video>
|
|
227
|
+
|
|
228
|
+
<!-- Overlay -->
|
|
229
|
+
<div class="overlay">
|
|
230
|
+
<div class="oval-mask" [class.border-red-500!]="isNotValidOval()"></div>
|
|
231
|
+
<p class="hint">{{ stepText() }}</p>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
`, isInline: true, styles: [":host{display:flex;align-items:center;justify-content:center;height:100vh;padding:1rem}.camera-wrapper{position:relative;width:100%;max-width:640px;aspect-ratio:4/3;margin:auto;overflow:hidden;border-radius:1rem;background:#65a0f8}.camera-video{width:100%;border-radius:12px}.overlay{position:absolute;inset:0;pointer-events:none;display:flex;flex-direction:column;align-items:center;justify-content:center}.oval-mask{width:50%;aspect-ratio:5/6;border-radius:50%;border:3px dashed #65a0f8;background:transparent;box-shadow:0 0 0 9999px #0009}.hint{margin-top:12px;color:#fff;font-size:14px;text-align:center;position:absolute;top:5px;background-color:#0000007a;padding:2px 4px;border-radius:5px}\n"] });
|
|
235
|
+
}
|
|
236
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: NgxFaceLiveness, decorators: [{
|
|
237
|
+
type: Component,
|
|
238
|
+
args: [{ selector: 'ngx-face-liveness', template: `
|
|
239
|
+
<div class="camera-wrapper">
|
|
240
|
+
<video #video autoplay muted playsinline class="camera-video"></video>
|
|
241
|
+
|
|
242
|
+
<!-- Overlay -->
|
|
243
|
+
<div class="overlay">
|
|
244
|
+
<div class="oval-mask" [class.border-red-500!]="isNotValidOval()"></div>
|
|
245
|
+
<p class="hint">{{ stepText() }}</p>
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
`, styles: [":host{display:flex;align-items:center;justify-content:center;height:100vh;padding:1rem}.camera-wrapper{position:relative;width:100%;max-width:640px;aspect-ratio:4/3;margin:auto;overflow:hidden;border-radius:1rem;background:#65a0f8}.camera-video{width:100%;border-radius:12px}.overlay{position:absolute;inset:0;pointer-events:none;display:flex;flex-direction:column;align-items:center;justify-content:center}.oval-mask{width:50%;aspect-ratio:5/6;border-radius:50%;border:3px dashed #65a0f8;background:transparent;box-shadow:0 0 0 9999px #0009}.hint{margin-top:12px;color:#fff;font-size:14px;text-align:center;position:absolute;top:5px;background-color:#0000007a;padding:2px 4px;border-radius:5px}\n"] }]
|
|
249
|
+
}], ctorParameters: () => [{ type: LivenessService }], propDecorators: { videoRef: [{
|
|
250
|
+
type: ViewChild,
|
|
251
|
+
args: ['video']
|
|
252
|
+
}], capturedImage: [{ type: i0.Output, args: ["capturedImage"] }] } });
|
|
253
|
+
|
|
254
|
+
/*
|
|
255
|
+
* Public API Surface of ngx-face-id
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Generated bundle index. Do not edit.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
export { NgxFaceLiveness };
|
|
263
|
+
//# sourceMappingURL=utamuratov-ngx-face-id.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utamuratov-ngx-face-id.mjs","sources":["../../../projects/ngx-face-id/src/lib/face-liveness/liveness.service.ts","../../../projects/ngx-face-id/src/lib/face-liveness/face-liveness.ts","../../../projects/ngx-face-id/src/public-api.ts","../../../projects/ngx-face-id/src/utamuratov-ngx-face-id.ts"],"sourcesContent":["import { computed, Injectable, signal } from '@angular/core';\nimport * as faceapi from 'face-api.js';\n\ntype Step =\n // | 'NO_FACE'\n // | 'OUTSIDE_OVAL'\n // | 'COME_CLOSE'\n // | 'VERY_CLOSE'\n 'BLINK' | 'MOUTH' | 'HEAD' | 'HOLD' | 'DONE';\n\ntype FaceInside = 'NO_FACE' | 'OUTSIDE_OVAL' | 'COME_CLOSE' | 'VERY_CLOSE' | 'VALID';\n\n@Injectable({ providedIn: 'root' })\nexport class LivenessService {\n private step = signal<Step>('BLINK');\n private faceInsideStatus = signal<FaceInside>('OUTSIDE_OVAL');\n currentStep = computed(() => this.step());\n currentFaceInsideStatus = computed(() => this.faceInsideStatus());\n\n private prevBlinkAvg = 0;\n private blinkCount = 0;\n private prevNoseX?: number;\n private holdStart?: number;\n\n async loadModels() {\n const MODEL_URL = '/models';\n await Promise.all([\n faceapi.nets.tinyFaceDetector.loadFromUri(MODEL_URL),\n faceapi.nets.faceLandmark68Net.loadFromUri(MODEL_URL),\n faceapi.nets.faceRecognitionNet.loadFromUri(MODEL_URL),\n ]);\n }\n\n reset() {\n this.faceInsideStatus.set('OUTSIDE_OVAL');\n this.step.set('BLINK');\n this.blinkCount = 0;\n this.prevBlinkAvg = 0;\n this.prevNoseX = undefined;\n this.holdStart = undefined;\n }\n\n // ---------- HELPERS ----------\n\n private isFaceInsideOval(box: faceapi.Box, video: HTMLVideoElement): boolean {\n const cx = video.videoWidth / 2;\n const cy = video.videoHeight / 2;\n\n // ✅ CSS: width: 50% → radius = 25%\n const rx = video.videoWidth * 0.25;\n const ry = rx * (6 / 5); // aspect-ratio: 5/6\n\n // 1️⃣ Yuzning 4 ta chekkasi oval ichida bo'lishi kerak\n const points = [\n { x: box.x, y: box.y + box.height / 2 }, // chap\n { x: box.x + box.width, y: box.y + box.height / 2 }, // o'ng\n { x: box.x + box.width / 2, y: box.y }, // tepa\n { x: box.x + box.width / 2, y: box.y + box.height }, // past\n ];\n\n const inside = points.every((p) => {\n const v = Math.pow(p.x - cx, 2) / Math.pow(rx, 2) + Math.pow(p.y - cy, 2) / Math.pow(ry, 2);\n return v <= 1;\n });\n\n if (!inside) {\n this.faceInsideStatus.set('OUTSIDE_OVAL');\n return false;\n }\n\n // 2️⃣ Yuz ovalni yaxshi to'ldirishi kerak (70-90%)\n const faceArea = box.width * box.height;\n const ovalArea = Math.PI * rx * ry;\n const fillRatio = faceArea / ovalArea;\n\n // Juda uzoq\n if (fillRatio < 0.4) {\n this.faceInsideStatus.set('COME_CLOSE');\n return false;\n }\n\n // Juda yaqin\n if (fillRatio > 0.59) {\n this.faceInsideStatus.set('VERY_CLOSE');\n return false;\n }\n\n this.faceInsideStatus.set('VALID');\n return true;\n }\n\n private dist(a: any, b: any) {\n return Math.hypot(a.x - b.x, a.y - b.y);\n }\n\n private eyeEAR(eye: faceapi.Point[]) {\n return (\n (this.dist(eye[1], eye[5]) + this.dist(eye[2], eye[4])) / (2 * this.dist(eye[0], eye[3]))\n );\n }\n\n private isBlink(lm: faceapi.FaceLandmarks68) {\n const left = this.eyeEAR(lm.getLeftEye());\n const right = this.eyeEAR(lm.getRightEye());\n const avg = (left + right) / 2;\n\n if (this.prevBlinkAvg === 0 || Math.abs(avg - this.prevBlinkAvg) < 0.01) {\n this.prevBlinkAvg = avg;\n return false;\n }\n\n this.prevBlinkAvg = avg;\n this.blinkCount++;\n return this.blinkCount > 2;\n }\n\n private isMouthOpen(lm: faceapi.FaceLandmarks68) {\n const mouth = lm.getMouth();\n return this.dist(mouth[13], mouth[19]) / this.dist(mouth[0], mouth[6]) > 0.4;\n }\n\n private isHeadMoved(lm: faceapi.FaceLandmarks68) {\n const nose = lm.getNose()[3];\n if (!this.prevNoseX) {\n this.prevNoseX = nose.x;\n return false;\n }\n const moved = Math.abs(nose.x - this.prevNoseX) > 30;\n\n this.prevNoseX = nose.x;\n return moved;\n }\n\n // ---------- MAIN CHECK ----------\n\n async process(video: HTMLVideoElement): Promise<boolean> {\n const result = await faceapi\n .detectSingleFace(video, new faceapi.TinyFaceDetectorOptions())\n .withFaceLandmarks();\n\n if (!result) {\n this.faceInsideStatus.set('NO_FACE');\n return false;\n }\n\n // 👇 OVAL CHECK\n const insideOval = this.isFaceInsideOval(result.detection.box, video);\n\n if (!insideOval) {\n if (this.step() === 'HOLD') {\n this.holdStart = Date.now();\n }\n return false;\n }\n\n const lm = result.landmarks;\n\n if (this.step() === 'BLINK' && this.isBlink(lm)) {\n this.step.set('MOUTH');\n } else if (this.step() === 'MOUTH' && this.isMouthOpen(lm)) {\n this.step.set('HEAD');\n } else if (this.step() === 'HEAD' && this.isHeadMoved(lm)) {\n this.step.set('HOLD');\n this.holdStart = Date.now();\n } else if (this.step() === 'HOLD') {\n if (!this.holdStart) this.holdStart = Date.now();\n if (Date.now() - this.holdStart > 3000) {\n this.step.set('DONE');\n return true; // 📸 CAPTURE SIGNAL\n }\n }\n\n return false;\n }\n}\n","import { Component, ElementRef, ViewChild, OnInit, computed, output } from '@angular/core';\nimport { LivenessService } from './liveness.service';\n\n@Component({\n selector: 'ngx-face-liveness',\n template: `\n <div class=\"camera-wrapper\">\n <video #video autoplay muted playsinline class=\"camera-video\"></video>\n\n <!-- Overlay -->\n <div class=\"overlay\">\n <div class=\"oval-mask\" [class.border-red-500!]=\"isNotValidOval()\"></div>\n <p class=\"hint\">{{ stepText() }}</p>\n </div>\n </div>\n `,\n styleUrls: ['./face-liveness.scss'],\n})\nexport class NgxFaceLiveness implements OnInit {\n @ViewChild('video') videoRef!: ElementRef<HTMLVideoElement>;\n intervalId: any;\n\n capturedImage = output<Blob>();\n\n constructor(private liveness: LivenessService) {}\n\n async ngOnInit() {\n await this.liveness.loadModels();\n await this.start();\n }\n\n currentStep = computed(() => this.liveness.currentStep());\n currentFaceInsideStatus = computed(() => this.liveness.currentFaceInsideStatus());\n isNotValidOval = computed(\n () =>\n this.currentFaceInsideStatus() === 'OUTSIDE_OVAL' ||\n this.currentFaceInsideStatus() === 'NO_FACE',\n );\n stepText = computed(() => {\n const currentFaceStatus = this.currentFaceInsideStatus();\n\n if (currentFaceStatus === 'NO_FACE') {\n return '❌ Yuz aniqlanmadi, iltimos, kameraga qarang';\n }\n if (currentFaceStatus === 'OUTSIDE_OVAL') {\n return '📐 Iltimos, yuzingizni oval ichiga joylashtiring';\n }\n if (currentFaceStatus === 'COME_CLOSE') {\n return '🔍 Iltimos, kameraga yaqinroq turing';\n }\n if (currentFaceStatus === 'VERY_CLOSE') {\n return '📷 Juda yaqin, kamerani orqaroq oling';\n }\n\n switch (this.currentStep()) {\n case 'BLINK':\n return '👁 Ko‘zingizni yumib oching(kamida 2 marta)';\n case 'MOUTH':\n return '🙂 Og‘zingizni ochib yuming (kamida yarim ochish kerak)';\n case 'HEAD':\n return '↔️ Boshni chapga yoki o‘ngga burang';\n case 'HOLD':\n return '✋ Barqaror turing (2 soniya)';\n default:\n return '✅ Tayyor!';\n }\n });\n\n async start() {\n this.liveness.reset();\n await this.openCamera();\n\n this.intervalId = setInterval(async () => {\n const done = await this.liveness.process(this.videoRef.nativeElement);\n\n if (done) {\n clearInterval(this.intervalId);\n const blob = await this.capture();\n this.sendToBackend(blob);\n }\n }, 300);\n }\n\n async openCamera() {\n const stream = await navigator.mediaDevices.getUserMedia({\n video: { facingMode: 'user' },\n });\n this.videoRef.nativeElement.srcObject = stream;\n }\n\n async capture(): Promise<Blob> {\n const video = this.videoRef.nativeElement;\n const canvas = document.createElement('canvas');\n\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n\n canvas.getContext('2d')!.drawImage(video, 0, 0);\n\n return new Promise((res) => canvas.toBlob((b) => res(b!), 'image/jpeg', 0.9));\n }\n\n sendToBackend(blob: Blob) {\n this.capturedImage.emit(blob);\n console.log(blob);\n\n // const fd = new FormData();\n // fd.append('file', blob, 'face.jpg');\n // this.http.post('/api/face/verify', fd).subscribe();\n }\n}\n","/*\r\n * Public API Surface of ngx-face-id\r\n */\r\n\r\nexport * from './lib/face-liveness/face-liveness';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.LivenessService"],"mappings":";;;;MAaa,eAAe,CAAA;AAClB,IAAA,IAAI,GAAG,MAAM,CAAO,OAAO,gDAAC;AAC5B,IAAA,gBAAgB,GAAG,MAAM,CAAa,cAAc,4DAAC;IAC7D,WAAW,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAA,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A,EAAA,CAAA,EAAA,YAAA,EAAA,UAAA,EAAA,KAAA,EAAA,IAAA,EAAA,SAAA,EAAA,CAAA,OAAA,CAAA,EAAA,WAAA,EAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAbhB;;;;;;;;;;AAUT,EAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,2rBAAA,CAAA,EAAA,CAAA;;2FAGU,eAAe,EAAA,UAAA,EAAA,CAAA;kBAf3B,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,mBAAmB,EAAA,QAAA,EACnB;;;;;;;;;;AAUT,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,2rBAAA,CAAA,EAAA;;sBAIA,SAAS;uBAAC,OAAO;;;ACnBpB;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@utamuratov/ngx-face-id",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Face Id liveness",
|
|
8
|
+
"author": "Odilbek Utamuratov",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/utamuratov/face-id.git"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@angular/common": ">=19.0.0",
|
|
15
|
+
"@angular/core": ">=19.0.0",
|
|
16
|
+
"face-api.js": "^0.23.0"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"tslib": "^2.3.0"
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"module": "fesm2022/utamuratov-ngx-face-id.mjs",
|
|
23
|
+
"typings": "types/utamuratov-ngx-face-id.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
"./package.json": {
|
|
26
|
+
"default": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./types/utamuratov-ngx-face-id.d.ts",
|
|
30
|
+
"default": "./fesm2022/utamuratov-ngx-face-id.mjs"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import { OnInit, ElementRef } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
type Step = 'BLINK' | 'MOUTH' | 'HEAD' | 'HOLD' | 'DONE';
|
|
5
|
+
type FaceInside = 'NO_FACE' | 'OUTSIDE_OVAL' | 'COME_CLOSE' | 'VERY_CLOSE' | 'VALID';
|
|
6
|
+
declare class LivenessService {
|
|
7
|
+
private step;
|
|
8
|
+
private faceInsideStatus;
|
|
9
|
+
currentStep: _angular_core.Signal<Step>;
|
|
10
|
+
currentFaceInsideStatus: _angular_core.Signal<FaceInside>;
|
|
11
|
+
private prevBlinkAvg;
|
|
12
|
+
private blinkCount;
|
|
13
|
+
private prevNoseX?;
|
|
14
|
+
private holdStart?;
|
|
15
|
+
loadModels(): Promise<void>;
|
|
16
|
+
reset(): void;
|
|
17
|
+
private isFaceInsideOval;
|
|
18
|
+
private dist;
|
|
19
|
+
private eyeEAR;
|
|
20
|
+
private isBlink;
|
|
21
|
+
private isMouthOpen;
|
|
22
|
+
private isHeadMoved;
|
|
23
|
+
process(video: HTMLVideoElement): Promise<boolean>;
|
|
24
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<LivenessService, never>;
|
|
25
|
+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<LivenessService>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare class NgxFaceLiveness implements OnInit {
|
|
29
|
+
private liveness;
|
|
30
|
+
videoRef: ElementRef<HTMLVideoElement>;
|
|
31
|
+
intervalId: any;
|
|
32
|
+
capturedImage: _angular_core.OutputEmitterRef<Blob>;
|
|
33
|
+
constructor(liveness: LivenessService);
|
|
34
|
+
ngOnInit(): Promise<void>;
|
|
35
|
+
currentStep: _angular_core.Signal<"BLINK" | "MOUTH" | "HEAD" | "HOLD" | "DONE">;
|
|
36
|
+
currentFaceInsideStatus: _angular_core.Signal<"NO_FACE" | "OUTSIDE_OVAL" | "COME_CLOSE" | "VERY_CLOSE" | "VALID">;
|
|
37
|
+
isNotValidOval: _angular_core.Signal<boolean>;
|
|
38
|
+
stepText: _angular_core.Signal<"❌ Yuz aniqlanmadi, iltimos, kameraga qarang" | "📐 Iltimos, yuzingizni oval ichiga joylashtiring" | "🔍 Iltimos, kameraga yaqinroq turing" | "📷 Juda yaqin, kamerani orqaroq oling" | "👁 Ko‘zingizni yumib oching(kamida 2 marta)" | "🙂 Og‘zingizni ochib yuming (kamida yarim ochish kerak)" | "↔️ Boshni chapga yoki o‘ngga burang" | "✋ Barqaror turing (2 soniya)" | "✅ Tayyor!">;
|
|
39
|
+
start(): Promise<void>;
|
|
40
|
+
openCamera(): Promise<void>;
|
|
41
|
+
capture(): Promise<Blob>;
|
|
42
|
+
sendToBackend(blob: Blob): void;
|
|
43
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgxFaceLiveness, never>;
|
|
44
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<NgxFaceLiveness, "ngx-face-liveness", never, {}, { "capturedImage": "capturedImage"; }, never, never, true, never>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { NgxFaceLiveness };
|