|
@@ -30,8 +30,8 @@ type DetectOutput = {
|
30
|
30
|
};
|
31
|
31
|
|
32
|
32
|
export interface FaceLandmarksHelper {
|
33
|
|
- detectFaceBox({ detections, threshold }: Detection): Promise<FaceBox | undefined>;
|
34
|
|
- detectFaceExpression({ detections }: Detection): Promise<string | undefined>;
|
|
33
|
+ getFaceBox({ detections, threshold }: Detection): FaceBox | undefined;
|
|
34
|
+ getFaceExpression({ detections }: Detection): string | undefined;
|
35
|
35
|
init(): Promise<void>;
|
36
|
36
|
detect({ image, threshold } : DetectInput): Promise<DetectOutput | undefined>;
|
37
|
37
|
getDetectionInProgress(): boolean;
|
|
@@ -118,7 +118,7 @@ export class HumanHelper implements FaceLandmarksHelper {
|
118
|
118
|
}
|
119
|
119
|
}
|
120
|
120
|
|
121
|
|
- async detectFaceBox({ detections, threshold }: Detection): Promise<FaceBox | undefined> {
|
|
121
|
+ getFaceBox({ detections, threshold }: Detection): FaceBox | undefined {
|
122
|
122
|
if (!detections.length) {
|
123
|
123
|
return;
|
124
|
124
|
}
|
|
@@ -140,7 +140,7 @@ export class HumanHelper implements FaceLandmarksHelper {
|
140
|
140
|
return faceBox;
|
141
|
141
|
}
|
142
|
142
|
|
143
|
|
- async detectFaceExpression({ detections }: Detection): Promise<string | undefined> {
|
|
143
|
+ getFaceExpression({ detections }: Detection): string | undefined {
|
144
|
144
|
if (detections[0]?.emotion) {
|
145
|
145
|
return FACE_EXPRESSIONS_NAMING_MAPPING[detections[0]?.emotion[0].emotion];
|
146
|
146
|
}
|
|
@@ -156,6 +156,7 @@ export class HumanHelper implements FaceLandmarksHelper {
|
156
|
156
|
}
|
157
|
157
|
|
158
|
158
|
this.detectionInProgress = true;
|
|
159
|
+ this.human.tf.engine().startScope();
|
159
|
160
|
|
160
|
161
|
const imageTensor = this.human.tf.browser.fromPixels(image);
|
161
|
162
|
|
|
@@ -163,7 +164,7 @@ export class HumanHelper implements FaceLandmarksHelper {
|
163
|
164
|
const { face } = await this.human.detect(imageTensor, this.config);
|
164
|
165
|
|
165
|
166
|
detections = face;
|
166
|
|
- faceExpression = await this.detectFaceExpression({ detections });
|
|
167
|
+ faceExpression = this.getFaceExpression({ detections });
|
167
|
168
|
}
|
168
|
169
|
|
169
|
170
|
if (this.faceDetectionTypes.includes(DETECTION_TYPES.FACE_BOX)) {
|
|
@@ -173,12 +174,13 @@ export class HumanHelper implements FaceLandmarksHelper {
|
173
|
174
|
detections = face;
|
174
|
175
|
}
|
175
|
176
|
|
176
|
|
- faceBox = await this.detectFaceBox({
|
|
177
|
+ faceBox = this.getFaceBox({
|
177
|
178
|
detections,
|
178
|
179
|
threshold
|
179
|
180
|
});
|
180
|
181
|
}
|
181
|
182
|
|
|
183
|
+ this.human.tf.engine().endScope();
|
182
|
184
|
this.detectionInProgress = false;
|
183
|
185
|
|
184
|
186
|
return {
|