2022-05-19 09:02:40 +00:00
|
|
|
import { DETECT_FACE, INIT_WORKER } from './constants';
|
|
|
|
import { FaceLandmarksHelper, HumanHelper }from './FaceLandmarksHelper';
|
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-05-19 09:02:40 +00:00
|
|
|
onmessage = async function(message: MessageEvent<any>) {
|
2022-05-06 12:41:08 +00:00
|
|
|
switch (message.data.type) {
|
|
|
|
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-05-19 09:02:40 +00:00
|
|
|
const detections = await helper.detect(message.data);
|
|
|
|
|
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-05-19 09:02:40 +00:00
|
|
|
helper = new HumanHelper(message.data);
|
2022-05-06 12:41:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|