2022-07-11 12:30:37 +00:00
|
|
|
import { FaceLandmarksHelper, HumanHelper } from './FaceLandmarksHelper';
|
2022-05-19 09:02:40 +00:00
|
|
|
import { DETECT_FACE, INIT_WORKER } from './constants';
|
2022-05-06 12:41:08 +00:00
|
|
|
|
2022-05-19 09:02:40 +00:00
|
|
|
let helper: FaceLandmarksHelper;
|
2022-05-06 12:41:08 +00:00
|
|
|
|
2022-09-14 12:42:46 +00:00
|
|
|
onmessage = async function({ data }: MessageEvent<any>) {
|
|
|
|
switch (data.type) {
|
2022-05-06 12:41:08 +00:00
|
|
|
case DETECT_FACE: {
|
2022-05-19 09:02:40 +00:00
|
|
|
if (!helper || helper.getDetectionInProgress()) {
|
2022-05-06 12:41:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-14 12:42:46 +00:00
|
|
|
const detections = await helper.detect(data);
|
2022-05-19 09:02:40 +00:00
|
|
|
|
2022-06-16 11:50:31 +00:00
|
|
|
if (detections && (detections.faceBox || detections.faceExpression || detections.faceCount)) {
|
2022-05-19 09:02:40 +00:00
|
|
|
self.postMessage(detections);
|
|
|
|
}
|
2022-05-06 12:41:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case INIT_WORKER: {
|
2022-09-14 12:42:46 +00:00
|
|
|
helper = new HumanHelper(data);
|
2022-05-06 12:41:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|