Skip to content

Commit

Permalink
Entry Js PUBLISH by v3.20230925.943
Browse files Browse the repository at this point in the history
  • Loading branch information
entrydev committed Sep 25, 2023
1 parent 3a7e3c5 commit 8c60207
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 9 additions & 1 deletion dist/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10681,6 +10681,7 @@ var MediaPipeUtils = /** @class */ (function () {
this.isInitPoseLandmarker = false;
this.alreadyInitPoseLandmarkerOffscreenCanvas = false;
this.isPrevFaceLandmarker = false;
this.isRunWorkerFaceLandmarker = false;
this.isRunningFaceLandmarker = false;
this.isDrawDetectedFaceLandmarker = false;
this.isInitFaceLandmarker = false;
Expand Down Expand Up @@ -11292,6 +11293,12 @@ var MediaPipeUtils = /** @class */ (function () {
}
_this.sendImageBitmapForFaceLandmarker();
}
else if (data.action === 'run_start_face_landmarker') {
_this.isRunWorkerFaceLandmarker = true;
}
else if (data.action === 'run_stop_face_landmarker') {
_this.isRunWorkerFaceLandmarker = false;
}
else if (data.action === 'start_face_landmarker') {
_this.isPrevFaceLandmarker = true;
Entry.engine.fireEvent('when_face_landmarker');
Expand Down Expand Up @@ -11548,7 +11555,7 @@ var MediaPipeUtils = /** @class */ (function () {
}, [this.faceLandmarkerOffscreenCanvas]);
this.alreadyInitFaceLandmarkerOffscreenCanvas = true;
}
else {
else if (!this.isRunWorkerFaceLandmarker) {
this.faceLandmarkerWorker.postMessage({
action: 'face_landmarker_restart',
});
Expand Down Expand Up @@ -11721,6 +11728,7 @@ var MediaPipeUtils = /** @class */ (function () {
});
this.isRunningFaceLandmarker = false;
this.isPrevFaceLandmarker = false;
this.isRunWorkerFaceLandmarker = false;
this.countDetectedFace = 0;
return [2 /*return*/];
});
Expand Down
2 changes: 1 addition & 1 deletion dist/entry.min.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions extern/face-landmarker.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ const drawOption = {

let flipState;
let isRun = false;
let isFirstIdle = false;

self.onmessage = async ({ data }) => {
if (data.action === 'face_landmarker_init') {
initializeFaceLandmarker(data);
} else if (data.action === 'face_landmarker_restart') {
isRun = true;
self.postMessage({ action: 'run_start_face_landmarker' });
} else if (data.action === 'face_landmarker_change_option') {
changeFaceLandmarkerOption(data.option);
} else if (data.action === 'face_landmarker') {
Expand All @@ -113,7 +115,6 @@ let isDrawDetectedFaceLandmarker = false;

const initializeFaceLandmarker = async (data) => {
const { canvas, option, isSafari, lang } = data;
isRun = true;
faceLang = lang.face;
isDrawDetectedFaceLandmarker = option.isDrawDetectedFaceLandmarker;
offCanvas = canvas;
Expand All @@ -125,7 +126,11 @@ const initializeFaceLandmarker = async (data) => {
}

if (!human) human = new Human.default(config);
await human.load(); // optional as models would be loaded on-demand first time they are required
await human.warmup(); // optional as model warmup is performed on-demand first time its executed

isRun = true;
self.postMessage({ action: 'run_start_face_landmarker' });
self.postMessage({ action: 'next_face_landmarker' });
};

Expand Down Expand Up @@ -166,10 +171,13 @@ const predictFaceLandmarker = async (imageBitmap) => {
if (!workerContext || !human) {
return;
}
const results = await human.detect(imageBitmap);
if (!isRun) {
if (!isFirstIdle && human.state === 'idle') {
isFirstIdle = true;
}
if (!isRun || !isFirstIdle) {
return;
}
const results = await human.detect(imageBitmap);
workerContext.save();
workerContext.clearRect(0, 0, 640, 360);

Expand Down Expand Up @@ -220,6 +228,7 @@ const predictFaceLandmarker = async (imageBitmap) => {
const clearPredictFaceLandmarker = () => {
console.log('clearPredictFaceLandmarker');
isRun = false;
self.postMessage({ action: 'run_stop_face_landmarker' });
isPrevFaceLandmarker = false;
countDetectedFace = 0;
workerContext.clearRect(0, 0, 640, 360);
Expand Down

0 comments on commit 8c60207

Please sign in to comment.