2022-10-20 09:11:27 +00:00
|
|
|
import { HumanHelper, IFaceLandmarksHelper } 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-10-20 09:11:27 +00:00
|
|
|
let helper: IFaceLandmarksHelper;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|