mirror of https://github.com/vladmandic/human
update node-video
parent
ebc9c72567
commit
5de785558b
|
@ -22,7 +22,6 @@ const userConfig = {
|
|||
},
|
||||
face: {
|
||||
enabled: true,
|
||||
// detector: { rotation: false, return: true, maxDetected: 50, iouThreshold: 0.206, minConfidence: 0.122 },
|
||||
detector: { return: true, rotation: true, maxDetected: 50, iouThreshold: 0.01, minConfidence: 0.2 },
|
||||
mesh: { enabled: true },
|
||||
iris: { enabled: false },
|
||||
|
|
|
@ -11,10 +11,11 @@
|
|||
* Working version of `ffmpeg` must be present on the system
|
||||
*/
|
||||
|
||||
const process = require('process');
|
||||
const spawn = require('child_process').spawn;
|
||||
const log = require('@vladmandic/pilogger'); // eslint-disable-line node/no-unpublished-require
|
||||
// in nodejs environments tfjs-node is required to be loaded before human
|
||||
const tf = require('@tensorflow/tfjs-node'); // eslint-disable-line node/no-unpublished-require
|
||||
// const tf = require('@tensorflow/tfjs-node'); // eslint-disable-line node/no-unpublished-require
|
||||
// const human = require('@vladmandic/human'); // use this when human is installed as module (majority of use cases)
|
||||
const Pipe2Jpeg = require('pipe2jpeg'); // eslint-disable-line node/no-missing-require, import/no-unresolved
|
||||
// const human = require('@vladmandic/human'); // use this when human is installed as module (majority of use cases)
|
||||
|
@ -22,7 +23,8 @@ const Human = require('../../dist/human.node.js'); // use this when using human
|
|||
|
||||
let count = 0; // counter
|
||||
let busy = false; // busy flag
|
||||
const inputFile = './test.mp4';
|
||||
let inputFile = './test.mp4';
|
||||
if (process.argv.length === 3) inputFile = process.argv[2];
|
||||
|
||||
const humanConfig = {
|
||||
modelBasePath: 'file://models/',
|
||||
|
@ -59,15 +61,16 @@ const ffmpegParams = [
|
|||
'pipe:1', // output to unix pipe that is then captured by pipe2jpeg
|
||||
];
|
||||
|
||||
async function process(jpegBuffer) {
|
||||
async function detect(jpegBuffer) {
|
||||
if (busy) return; // skip processing if busy
|
||||
busy = true;
|
||||
const tensor = human.tf.node.decodeJpeg(jpegBuffer, 3); // decode jpeg buffer to raw tensor
|
||||
log.state('input frame:', ++count, 'size:', jpegBuffer.length, 'decoded shape:', tensor.shape);
|
||||
const res = await human.detect(tensor);
|
||||
log.data('gesture', JSON.stringify(res.gesture));
|
||||
// do processing here
|
||||
tf.dispose(tensor); // must dispose tensor
|
||||
human.tf.dispose(tensor); // must dispose tensor
|
||||
// start custom processing here
|
||||
log.data('frame', { frame: ++count, size: jpegBuffer.length, shape: tensor.shape, face: res?.face?.length, body: res?.body?.length, hand: res?.hand?.length, gesture: res?.gesture?.length });
|
||||
if (res?.face?.[0]) log.data('person', { score: [res.face[0].boxScore, res.face[0].faceScore], age: res.face[0].age || 0, gender: [res.face[0].genderScore || 0, res.face[0].gender], emotion: res.face[0].emotion?.[0] });
|
||||
// at the of processing mark loop as not busy so it can process next frame
|
||||
busy = false;
|
||||
}
|
||||
|
||||
|
@ -75,8 +78,9 @@ async function main() {
|
|||
log.header();
|
||||
await human.tf.ready();
|
||||
// pre-load models
|
||||
log.info('human:', human.version, 'tf:', tf.version_core);
|
||||
pipe2jpeg.on('jpeg', (jpegBuffer) => process(jpegBuffer));
|
||||
log.info({ human: human.version, tf: human.tf.version_core });
|
||||
log.info({ input: inputFile });
|
||||
pipe2jpeg.on('data', (jpegBuffer) => detect(jpegBuffer));
|
||||
|
||||
const ffmpeg = spawn('ffmpeg', ffmpegParams, { stdio: ['ignore', 'pipe', 'ignore'] });
|
||||
ffmpeg.on('error', (error) => log.error('ffmpeg error:', error));
|
||||
|
|
16
package.json
16
package.json
|
@ -18,11 +18,17 @@
|
|||
"script": "./dist/human.js",
|
||||
"module": "./dist/human.esm.js",
|
||||
"types": "./types/human.d.ts",
|
||||
"dist/human": "./dist/human.js",
|
||||
"dist/human.js": "./dist/human.js",
|
||||
"dist/human.esm": "./dist/human.esm.js",
|
||||
"dist/human.esm.js": "./dist/human.esm.js",
|
||||
"dist/human.esm-nobundle": "./dist/human.esm-nobundle.js",
|
||||
"dist/human.esm-nobundle.js": "./dist/human.esm-nobundle.js",
|
||||
"dist/human.node": "./dist/human.node.js",
|
||||
"dist/human.node.js": "./dist/human.node.js",
|
||||
"dist/human.node-wasm": "./dist/human.node-wasm.js",
|
||||
"dist/human.node-wasm.js": "./dist/human.node-wasm.js",
|
||||
"dist/human.node-gpu": "./dist/human.node-gpu.js",
|
||||
"dist/human.node-gpu.js": "./dist/human.node-gpu.js"
|
||||
},
|
||||
"author": "Vladimir Mandic <mandic00@live.com>",
|
||||
|
@ -83,15 +89,15 @@
|
|||
"@tensorflow/tfjs-core": "^4.1.0",
|
||||
"@tensorflow/tfjs-node": "^4.1.0",
|
||||
"@tensorflow/tfjs-node-gpu": "^4.1.0",
|
||||
"@types/node": "^18.11.17",
|
||||
"@types/node": "^18.11.18",
|
||||
"@types/offscreencanvas": "^2019.7.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
||||
"@typescript-eslint/parser": "^5.47.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"@vladmandic/build": "^0.7.14",
|
||||
"@vladmandic/pilogger": "^0.4.6",
|
||||
"@vladmandic/tfjs": "github:vladmandic/tfjs",
|
||||
"canvas": "^2.10.2",
|
||||
"esbuild": "^0.16.10",
|
||||
"canvas": "^2.11.0",
|
||||
"esbuild": "^0.16.12",
|
||||
"eslint": "8.30.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-html": "^7.1.0",
|
||||
|
|
2001
test/test.log
2001
test/test.log
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue