mirror of https://github.com/vladmandic/human
switch worker from module to iife importscripts
parent
c0a7288a3f
commit
b05cb22062
|
@ -1,7 +1,11 @@
|
|||
import Human from '../dist/human.esm.js';
|
||||
// load Human using IIFE script as Chome Mobile does not support Modules as Workers
|
||||
// import Human from '../dist/human.esm.js';
|
||||
self.importScripts('../dist/human.js');
|
||||
|
||||
let busy = false;
|
||||
const human = new Human();
|
||||
// @ts-ignore // Human is registered as global namespace using IIFE script
|
||||
// eslint-disable-next-line no-undef, new-cap
|
||||
const human = new Human.default();
|
||||
|
||||
function log(...msg) {
|
||||
const dt = new Date();
|
||||
|
|
|
@ -387,7 +387,9 @@ function webWorker(input, image, canvas, timestamp) {
|
|||
if (!worker) {
|
||||
// create new webworker and add event handler only once
|
||||
log('creating worker thread');
|
||||
worker = new Worker(ui.worker, { type: 'module' });
|
||||
// load Human using IIFE script as Chome Mobile does not support Modules as Workers
|
||||
// worker = new Worker(ui.worker, { type: 'module' });
|
||||
worker = new Worker(ui.worker);
|
||||
// after receiving message from webworker, parse&draw results and send new frame for processing
|
||||
worker.addEventListener('message', (msg) => {
|
||||
if (msg.data.result.performance && msg.data.result.performance.total) ui.detectFPS.push(1000 / msg.data.result.performance.total);
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -10372,7 +10372,8 @@ function join2(faces, bodies, hands, gestures, shape) {
|
|||
var bufferedResult = { face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0 };
|
||||
function calc(newResult) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
||||
const bufferedFactor = 1e3 / (Date.now() - newResult.timestamp) / 4;
|
||||
const elapsed = Date.now() - newResult.timestamp;
|
||||
const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed) : 1;
|
||||
if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) {
|
||||
bufferedResult.body = JSON.parse(JSON.stringify(newResult.body));
|
||||
} else {
|
||||
|
|
|
@ -10373,7 +10373,8 @@ function join2(faces, bodies, hands, gestures, shape) {
|
|||
var bufferedResult = { face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0 };
|
||||
function calc(newResult) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
||||
const bufferedFactor = 1e3 / (Date.now() - newResult.timestamp) / 4;
|
||||
const elapsed = Date.now() - newResult.timestamp;
|
||||
const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed) : 1;
|
||||
if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) {
|
||||
bufferedResult.body = JSON.parse(JSON.stringify(newResult.body));
|
||||
} else {
|
||||
|
|
|
@ -10372,7 +10372,8 @@ function join2(faces, bodies, hands, gestures, shape) {
|
|||
var bufferedResult = { face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0 };
|
||||
function calc(newResult) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
||||
const bufferedFactor = 1e3 / (Date.now() - newResult.timestamp) / 4;
|
||||
const elapsed = Date.now() - newResult.timestamp;
|
||||
const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed) : 1;
|
||||
if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) {
|
||||
bufferedResult.body = JSON.parse(JSON.stringify(newResult.body));
|
||||
} else {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,15 @@ export function calc(newResult: Result): Result {
|
|||
// otherwise bufferedResult is a shallow clone of result plus updated local calculated values
|
||||
// thus mixing by-reference and by-value assignments to minimize memory operations
|
||||
|
||||
const bufferedFactor = 1000 / (Date.now() - newResult.timestamp) / 4;
|
||||
const elapsed = Date.now() - newResult.timestamp;
|
||||
// curve fitted: buffer = 8 - ln(delay)
|
||||
// interpolation formula: current = ((buffer - 1) * previous + live) / buffer
|
||||
// - at 50ms delay buffer = ~4.1 => 28% towards live data
|
||||
// - at 250ms delay buffer = ~2.5 => 40% towards live data
|
||||
// - at 500ms delay buffer = ~1.8 => 55% towards live data
|
||||
// - at 750ms delay buffer = ~1.4 => 71% towards live data
|
||||
// - at 1sec delay buffer = 1 which means live data is used
|
||||
const bufferedFactor = elapsed < 1000 ? 8 - Math.log(elapsed) : 1;
|
||||
|
||||
// interpolate body results
|
||||
if (!bufferedResult.body || (newResult.body.length !== bufferedResult.body.length)) {
|
||||
|
|
Loading…
Reference in New Issue