You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

faceLandmarksWorker.ts 712B

12345678910111213141516171819202122232425262728
  1. import { FaceLandmarksHelper, HumanHelper } from './FaceLandmarksHelper';
  2. import { DETECT_FACE, INIT_WORKER } from './constants';
  3. let helper: FaceLandmarksHelper;
  4. onmessage = async function(message: MessageEvent<any>) {
  5. switch (message.data.type) {
  6. case DETECT_FACE: {
  7. if (!helper || helper.getDetectionInProgress()) {
  8. return;
  9. }
  10. const detections = await helper.detect(message.data);
  11. if (detections && (detections.faceBox || detections.faceExpression || detections.faceCount)) {
  12. self.postMessage(detections);
  13. }
  14. break;
  15. }
  16. case INIT_WORKER: {
  17. helper = new HumanHelper(message.data);
  18. break;
  19. }
  20. }
  21. };