From 7f5007851ed4d7035c9df51850f0bc212a43908d Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 18 Nov 2020 09:15:03 -0500 Subject: [PATCH] optimize camera resize on mobile --- demo/browser.js | 21 ++++++++++----------- demo/index.html | 2 +- demo/menu.js | 2 +- package.json | 3 +-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/demo/browser.js b/demo/browser.js index 84575e86..65126e0f 100644 --- a/demo/browser.js +++ b/demo/browser.js @@ -136,7 +136,7 @@ async function drawResults(input) { const avgDraw = Math.trunc(10 * ui.drawFPS.reduce((a, b) => a + b, 0) / ui.drawFPS.length) / 10; const warning = (ui.detectFPS.length > 5) && (avgDetect < 5) ? 'warning: your performance is low: try switching to higher performance backend, lowering resolution or disabling some models' : ''; document.getElementById('log').innerHTML = ` - video: ${ui.camera.name} | facing: ${ui.camera.facing} | resolution: ${ui.camera.width} x ${ui.camera.height} ${processing}
+ video: ${ui.camera.name} | facing: ${ui.camera.facing} | screen: ${window.innerWidth} x ${window.innerHeight} camera: ${ui.camera.width} x ${ui.camera.height} ${processing}
backend: ${human.tf.getBackend()} | ${memory}
performance: ${str(result.performance)} FPS process:${avgDetect} refresh:${avgDraw}
${warning} @@ -178,16 +178,11 @@ async function setupCamera() { let stream; const constraints = { audio: false, - video: { - facingMode: ui.facing ? 'user' : 'environment', - resizeMode: ui.crop ? 'crop-and-scale' : 'none', - width: { ideal: window.innerWidth }, - height: { ideal: window.innerHeight }, - }, + video: { facingMode: ui.facing ? 'user' : 'environment', resizeMode: ui.crop ? 'crop-and-scale' : 'none' }, }; + if (window.innerWidth > window.innerHeight) constraints.video.width = { ideal: window.innerWidth }; + else constraints.video.height = { ideal: window.innerHeight }; try { - // if (window.innerWidth > window.innerHeight) constraints.video.width = { ideal: window.innerWidth }; - // else constraints.video.height = { ideal: window.innerHeight }; stream = await navigator.mediaDevices.getUserMedia(constraints); } catch (err) { if (err.name === 'PermissionDeniedError') msg = 'camera permission denied'; @@ -376,8 +371,8 @@ function setupMenu() { menu.addHTML('
'); menu.addList('backend', ['cpu', 'webgl', 'wasm'], human.config.backend, (val) => human.config.backend = val); menu.addBool('async operations', human.config, 'async', (val) => human.config.async = val); - menu.addBool('enable profiler', human.config, 'profile', (val) => human.config.profile = val); - menu.addBool('memory shield', human.config, 'deallocate', (val) => human.config.deallocate = val); + // menu.addBool('enable profiler', human.config, 'profile', (val) => human.config.profile = val); + // menu.addBool('memory shield', human.config, 'deallocate', (val) => human.config.deallocate = val); menu.addBool('use web worker', ui, 'useWorker'); menu.addHTML('
'); menu.addLabel('enabled models'); @@ -387,6 +382,10 @@ function setupMenu() { menu.addBool('face age', human.config.face.age, 'enabled'); menu.addBool('face gender', human.config.face.gender, 'enabled'); menu.addBool('face emotion', human.config.face.emotion, 'enabled'); + // menu.addBool('face compare', human.config.face.embedding, 'enabled', (val) => { + // human.config.face.embedding.enabled = val; + // document.getElementById('compare-container').style.display = human.config.face.embedding.enabled ? 'block' : 'none'; + // }); menu.addBool('body pose', human.config.body, 'enabled'); menu.addBool('hand pose', human.config.hand, 'enabled'); menu.addBool('gesture analysis', human.config.gesture, 'enabled'); diff --git a/demo/index.html b/demo/index.html index 633de390..1e12b8c6 100644 --- a/demo/index.html +++ b/demo/index.html @@ -6,7 +6,7 @@ - + diff --git a/demo/menu.js b/demo/menu.js index 32d91f27..e41845f8 100644 --- a/demo/menu.js +++ b/demo/menu.js @@ -19,7 +19,7 @@ function createCSS() { if (CSScreated) return; const css = ` :root { --rounded: 0.2rem; } - .menu { position: absolute; top: 0rem; right: 0; width: fit-content; padding: 0 0.8rem 0 0.8rem; line-height: 1.8rem; z-index: 10; max-height: calc(100% - 4rem); + .menu { position: absolute; top: 0rem; right: 0; width: fit-content; padding: 0 0.8rem 0 0.8rem; line-height: 1.8rem; z-index: 10; box-shadow: 0 0 8px dimgrey; background: ${theme.background}; border-radius: var(--rounded); border-color: black; border-style: solid; border-width: thin; } .menu:hover { box-shadow: 0 0 8px ${theme.hover}; } diff --git a/package.json b/package.json index 83a3505e..e1b32fa0 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,7 @@ "type": "git", "url": "git+https://github.com/vladmandic/human.git" }, - "dependencies": { - }, + "dependencies": {}, "peerDependencies": {}, "devDependencies": { "@tensorflow/tfjs-backend-cpu": "^2.7.0",