Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(face-landmarks): filter face detections based on detection score (#11658)
Gabriel Borlea9383942cb9bb
diff --git a/react/features/face-landmarks/FaceLandmarksHelper.ts b/react/features/face-landmarks/FaceLandmarksHelper.tsindex 7ce2121498..0b90b369d0 100644--- a/react/features/face-landmarks/FaceLandmarksHelper.ts+++ b/react/features/face-landmarks/FaceLandmarksHelper.ts@@ -1,7 +1,7 @@import { setWasmPaths } from '@tensorflow/tfjs-backend-wasm';import { Human, Config, FaceResult } from '@vladmandic/human';-import { DETECTION_TYPES, FACE_EXPRESSIONS_NAMING_MAPPING } from './constants';+import { DETECTION_TYPES, FACE_DETECTION_SCORE_THRESHOLD, FACE_EXPRESSIONS_NAMING_MAPPING } from './constants';type Detection = {detections: Array<FaceResult>,@@ -130,7 +130,7 @@ export class HumanHelper implements FaceLandmarksHelper {if (!detections.length) {return;}-+const faceBox: FaceBox = {// normalize to percentage basedleft: Math.round(Math.min(...detections.map(d => d.boxRaw[0])) * 100),@@ -154,41 +154,49 @@ export class HumanHelper implements FaceLandmarksHelper {}}+ async getDetections(image: ImageBitmap | ImageData) {+ if (!this.human) {+ return;+ }++ this.human.tf.engine().startScope();++ const imageTensor = this.human.tf.browser.fromPixels(image);+ const { face: detections } = await this.human.detect(imageTensor, this.config);++ this.human.tf.engine().endScope();++ return detections.filter(detection => detection.score > FACE_DETECTION_SCORE_THRESHOLD);+ }+public async detect({ image, threshold } : DetectInput): Promise<DetectOutput | undefined> {let detections;let faceExpression;let faceBox;- if (!this.human){- return;- }-this.detectionInProgress = true;- this.human.tf.engine().startScope();-- const imageTensor = this.human.tf.browser.fromPixels(image);if (this.faceDetectionTypes.includes(DETECTION_TYPES.FACE_EXPRESSIONS)) {- const { face } = await this.human.detect(imageTensor, this.config);+ detections = await this.getDetections(image);- detections = face;- faceExpression = this.getFaceExpression({ detections });+ if (detections) {+ faceExpression = this.getFaceExpression({ detections });+ }}if (this.faceDetectionTypes.includes(DETECTION_TYPES.FACE_BOX)) {if (!detections) {- const { face } = await this.human.detect(imageTensor, this.config);-- detections = face;+ detections = await this.getDetections(image);}- faceBox = this.getFaceBox({- detections,- threshold- });+ if(detections) {+ faceBox = this.getFaceBox({+ detections,+ threshold+ });+ }}-- this.human.tf.engine().endScope();+this.detectionInProgress = false;return {diff --git a/react/features/face-landmarks/constants.ts b/react/features/face-landmarks/constants.tsindex 8747932716..36ae27ca5d 100644--- a/react/features/face-landmarks/constants.ts+++ b/react/features/face-landmarks/constants.ts@@ -55,3 +55,8 @@ export const DETECTION_TYPES = {FACE_BOX: 'face-box',FACE_EXPRESSIONS: 'face-expressions'};++/**+ * Threshold for detection score of face.+ */+export const FACE_DETECTION_SCORE_THRESHOLD = 0.6;\ No newline at end of file