### Webcam Integration with Human.js Source: https://github.com/vladmandic/human/wiki/Home This example demonstrates using Human's built-in webcam helper methods for complete video handling. It starts the webcam, begins detection using `human.video`, and draws results with interpolation. ```javascript const human = new Human(); const outputCanvas = document.getElementById('canvas-id'); async function drawResults() { const interpolated = human.next(); human.draw.canvas(outputCanvas, human.webcam.element); human.draw.all(outputCanvas, interpolated); requestAnimationFrame(drawResults); } await human.webcam.start({ crop: true }); human.video(human.webcam.element); drawResults(); ``` -------------------------------- ### Install Docker using Convenience Script Source: https://github.com/vladmandic/human/wiki/Docker Installs Docker using the official convenience script. Ensure you have curl installed. ```bash curl https://get.docker.com | sudo sh ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/vladmandic/human/wiki/Build-Process Use these commands to clone the repository, navigate into the directory, install all project dependencies, and then run the build process. ```shell git clone https://github.com/vladmandic/human cd human npm install --dev # installs all project dependencies npm run build ``` -------------------------------- ### start Source: https://github.com/vladmandic/human/blob/main/typedoc/interfaces/WebCam.html Initializes the webcam stream and associates it with a DOM video element. ```APIDOC ## start ### Description Initializes the webcam stream and associates it with a DOM video element. ### Method `start(webcamConfig?: Partial): Promise` ### Parameters #### Optional Parameters * `webcamConfig` (Partial<[WebCamConfig](WebCamConfig.html)\>) - Optional configuration object for the webcam. ### Returns `Promise` - A promise that resolves with the ID of the started webcam stream. ### Example ```typescript const streamId = await webcam.start({ element: document.getElementById('videoElement') }); console.log(`Webcam stream started with ID: ${streamId}`); ``` ``` -------------------------------- ### Install Human Library for Browser and NodeJS Source: https://context7.com/vladmandic/human/llms.txt Install the Human library using NPM. For NodeJS, ensure a TensorFlow.js backend is installed separately. ```bash # Browser (bundler workflow) npm install @vladmandic/human ``` ```bash # NodeJS (CPU) npm install @vladmandic/human @tensorflow/tfjs-node ``` ```bash # NodeJS (GPU / CUDA) npm install @vladmandic/human @tensorflow/tfjs-node-gpu ``` -------------------------------- ### NodeJS Face Matching Performance Example Source: https://github.com/vladmandic/human/blob/main/demo/facematch/README.md This example demonstrates the output logs from running the NodeJS face matching demo. It shows configuration options, buffer creation, database loading, worker thread pool initialization, and job processing statistics. ```js INFO: options: { dbFile: './faces.json', dbMax: 10000, threadPoolSize: 6, workerSrc: './node-match-worker.js', debug: false, minThreshold: 0.9, descLength: 1024 } DATA: created shared buffer: { maxDescriptors: 10000, totalBytes: 40960000, totalElements: 10240000 } DATA: db loaded: { existingRecords: 0, newRecords: 5700 } INFO: starting worker thread pool: { totalWorkers: 6, alreadyActive: 0 } STATE: submitted: { matchJobs: 100, poolSize: 6, activeWorkers: 6 } STATE: { matchJobsFinished: 100, totalTimeMs: 1769, averageTimeMs: 17.69 } INFO: closing workers: { poolSize: 6, activeWorkers: 6 } ``` -------------------------------- ### Install Human with npm Source: https://github.com/vladmandic/human/wiki/Install Install the Human library using npm for use with bundlers. ```shell npm install @vladmandic/human ``` -------------------------------- ### Custom Configuration Example Source: https://github.com/vladmandic/human/wiki/Config Demonstrates how to create a custom configuration object to override default settings, such as specifying a model base path and enabling segmentation. ```javascript const myConfig = { modelBasePath: 'https://cdn.jsdelivr.net/npm/@vladmandic/human/models/', segmentation: { enabled: true }, }; const human = new Human(myConfig); const result = await human.detect(input); ``` -------------------------------- ### Main Entry Point and Webcam Initialization Source: https://github.com/vladmandic/human/blob/main/demo/video/index.html The main function initializes the Human library, starts the webcam, sets up the canvas, and begins the drawing loop. It also includes an event listener to pause/resume the webcam feed on click. ```javascript async function main() { // main entry point document.getElementById('log').innerHTML = `human version: ${human.version} | tfjs version: ${human.tf.version['tfjs-core']}
platform: ${human.env.platform} | agent ${human.env.agent}`; await human.webcam.start({ crop: true }); // find webcam and start it human.video(human.webcam.element); // instruct human to continously detect video frames canvas.width = human.webcam.width; // set canvas resolution to input webcam native resolution canvas.height = human.webcam.height; canvas.onclick = async () => { // pause when clicked on screen and resume on next click if (human.webcam.paused) await human.webcam.play(); else human.webcam.pause(); }; await drawLoop(); // start draw loop } window.onload = main; ``` -------------------------------- ### Install Human and TFJS for No-Bundle Source: https://github.com/vladmandic/human/wiki/Install Install both Human and TensorFlow.js when you intend to bundle TFJS separately. ```shell npm install @vladmandic/human @tensorflow/tfjs ``` -------------------------------- ### Example Gesture Output Source: https://github.com/vladmandic/human/wiki/Gesture This is an example of the output format for detected gestures, indicating the type of gesture and the person it belongs to. ```js gesture = [ { face: '0', gesture: 'facing camera' }, { face: '0', gesture: 'head up' }, { iris: '0', gesture: 'looking center' }, { body: '0', gesture: 'i give up' }, { body: '0', gesture: 'leaning left' }, { hand: '0', gesture: 'thumb forward middlefinger up' }, ]; ``` -------------------------------- ### Initialize Human Library with Configuration Source: https://github.com/vladmandic/human/blob/main/demo/video/index.html Import the Human library and configure its behavior. This setup is essential for fine-tuning detection models and enabling specific features like face, body, or hand tracking. ```javascript import * as H from '../../dist/human.esm.js'; const humanConfig = { // user configuration for human, used to fine-tune behavior modelBasePath: '../../models', filter: { enabled: true, equalization: true, flip: false }, face: { enabled: true, detector: { rotation: false }, mesh: { enabled: true }, attention: { enabled: false }, iris: { enabled: true }, description: { enabled: true }, emotion: { enabled: true }, }, body: { enabled: true }, hand: { enabled: true }, gesture: { enabled: true }, object: { enabled: false }, segmentation: { enabled: false }, }; const human = new H.Human(humanConfig); ``` -------------------------------- ### Check Docker Installation Status Source: https://github.com/vladmandic/human/wiki/Docker Verifies Docker installation by checking its version, system info, and service status. ```bash sudo docker version ``` ```bash sudo docker info ``` ```bash sudo systemctl status containerd docker ``` -------------------------------- ### Basic Video Detection with Human.js Source: https://github.com/vladmandic/human/wiki/Home This example shows how to initialize Human, select input/output elements, and perform basic video detection using Promises. It draws detected faces, bodies, hands, and gestures to the output canvas. ```javascript const config = { backend: 'webgl' }; const human = new Human.Human(config); const inputVideo = document.getElementById('video-id'); const outputCanvas = document.getElementById('canvas-id'); function detectVideo() { human.detect(inputVideo).then((result) => { human.draw.canvas(result.canvas, outputCanvas); human.draw.face(outputCanvas, result.face); human.draw.body(outputCanvas, result.body); human.draw.hand(outputCanvas, result.hand); human.draw.gesture(outputCanvas, result.gesture); requestAnimationFrame(detectVideo); return result; }); } detectVideo(); ``` -------------------------------- ### Full Video Processing with Human.js Source: https://github.com/vladmandic/human/wiki/Home This example uses Human's built-in full video processing, eliminating the need for manual frame-by-frame loops. It starts the detection loop with `human.video` and uses `human.next` for interpolated results in the drawing loop. ```javascript const human = new Human(); const inputVideo = document.getElementById('video-id'); const outputCanvas = document.getElementById('canvas-id'); async function drawResults() { const interpolated = human.next(); human.draw.all(outputCanvas, interpolated); requestAnimationFrame(drawResults); } human.video(inputVideo); drawResults(); ``` -------------------------------- ### Development Server Log Output Source: https://github.com/vladmandic/human/wiki/Development-Server Example log output from the development server, showing environment details, toolchain versions, and server states. ```log 2021-09-10 21:03:37 INFO: @vladmandic/human version 2.1.5 2021-09-10 21:03:37 INFO: User: vlado Platform: linux Arch: x64 Node: v16.5.0 2021-09-10 21:03:37 INFO: Application: { name: '@vladmandic/human', version: '2.1.5' } 2021-09-10 21:03:37 INFO: Environment: { profile: 'development', config: 'build.json', tsconfig: true, eslintrc: true, git: true } 2021-09-10 21:03:37 INFO: Toolchain: { build: '0.3.4', esbuild: '0.12.26', typescript: '4.4.3', typedoc: '0.21.9', eslint: '7.32.0' } 2021-09-10 21:03:37 STATE: WebServer: { ssl: false, port: 10030, root: '.' } 2021-09-10 21:03:37 STATE: WebServer: { ssl: true, port: 10031, root: '.', sslKey: 'node_modules/@vladmandic/build/cert/https.key', sslCrt: 'node_modules/@vladmandic/build/cert/https.crt' } 2021-09-10 21:03:37 STATE: Watch: { locations: [ 'test/src/**', 'src/**', 'tfjs/*', [length]: 3 ] } 2021-09-10 21:03:37 STATE: Watch: { locations: [ 'test/src/**', 'src/**', 'tfjs/*', [length]: 3 ] } 2021-09-10 21:03:37 STATE: Watch: { locations: [ 'test/src/**', 'src/**', 'tfjs/*', [length]: 3 ] } 2021-09-10 21:07:48 INFO: Watch: { event: 'modify', input: 'src/human.ts' } 2021-09-10 21:07:48 STATE: Build: { name: 'tfjs for browser esm bundle', type: 'development', format: 'esm', platform: 'browser', input: 'tfjs/tf-browser.ts', output: 'dist/tfjs.esm.js', files: 7, inputBytes: 2168, outputBytes: 2343946 } 2021-09-10 21:07:49 STATE: Build: { name: 'human for browser esm bundle', type: 'development', format: 'esm', platform: 'browser', input: 'src/human.ts', output: 'dist/human.esm.js', files: 47, inputBytes: 2799374, outputBytes: 2583497 } 2021-09-10 21:07:31 DATA: GET/1.1 200 text/html; charset=utf-8 6435 / ::ffff:192.168.0.200 2021-09-10 21:07:31 DATA: GET/1.1 200 text/css; charset=utf-8 107884 /icons.css ::ffff:192.168.0.200 2021-09-10 21:07:31 DATA: GET/1.1 200 text/javascript; charset=utf-8 44675 /index.js ::ffff:192.168.0.200 2021-09-10 21:07:31 DATA: GET/1.1 200 text/javascript; charset=utf-8 2583497 /dist/human.esm.js ::ffff:192.168.0.200 ... ``` -------------------------------- ### init() Source: https://github.com/vladmandic/human/blob/main/typedoc/functions/draw.init.html Initializes default label templates for face, body, hand, object, and gestures. This function is typically called once during application setup. ```APIDOC ## Function: init() ### Description Sets default label templates for face, body, hand, object, and gestures. ### Signature `init(): void[]` ### Returns `void[]` - An array of void, indicating no specific return value. ### Source Defined in `src/draw/draw.ts:100` ``` -------------------------------- ### Install Human with tfjs-node Source: https://github.com/vladmandic/human/wiki/Install Install the Human library and the TensorFlow.js Node.js backend for CPU execution. This is recommended for Node.js projects running on the backend. ```shell npm install @vladmandic/human @tensorflow/tfjs-node ``` -------------------------------- ### Install Human with tfjs-node-gpu Source: https://github.com/vladmandic/human/wiki/Install Install the Human library and the TensorFlow.js Node.js GPU backend for accelerated execution. Requires a compatible CUDA environment. ```shell npm install @vladmandic/human @tensorflow/tfjs-node-gpu ``` -------------------------------- ### Video Detection with Human.js using Async/Await Source: https://github.com/vladmandic/human/wiki/Home This example demonstrates video detection using async/await syntax for cleaner asynchronous code. It initializes Human, selects video and canvas elements, and uses `human.draw.all` to draw all detected results. ```javascript const config = { backend: 'webgl' }; const human = new Human(config); const inputVideo = document.getElementById('video-id'); const outputCanvas = document.getElementById('canvas-id'); async function detectVideo() { const result = await human.detect(inputVideo); human.draw.all(outputCanvas, result); requestAnimationFrame(detectVideo); } detectVideo(); ``` -------------------------------- ### Load Human Library from CDN in Browser Source: https://context7.com/vladmandic/human/llms.txt Load the Human library directly from a CDN for browser use without needing an NPM installation. Initialize the Human instance with a specified backend. ```html ``` -------------------------------- ### Webcam and Drawing Helper Methods Source: https://github.com/vladmandic/human/wiki/Usage Helper namespaces for controlling webcam functionality (start, stop, play, pause) and drawing detection results to a canvas. ```javascript human.webcam.* // helper methods to control webcam, main properties are `start`, `stop`, `play`, `pause` ``` ```javascript human.draw.* // helper methods to draw detected results to canvas, main options are `options`, `canvas`, `all` ``` -------------------------------- ### Run NodeJS Multi-process Demo Source: https://github.com/vladmandic/human/blob/main/demo/multithread/README.md Execute the NodeJS multi-process demo to see parallel execution of the Human library across multiple worker processes. This example uses CommonJS modules. ```shell node demo/nodejs/node-multiprocess.js ``` -------------------------------- ### NodeJS Multi-process Demo Output Source: https://github.com/vladmandic/human/blob/main/demo/multithread/README.md Example output from the NodeJS multi-process demo, showing worker initialization, message dispatching, and processing results. This demonstrates the parallel processing capabilities. ```json 2021-06-01 08:54:19 INFO: @vladmandic/human version 2.0.0 2021-06-01 08:54:19 INFO: User: vlado Platform: linux Arch: x64 Node: v16.0.0 2021-06-01 08:54:19 INFO: Human multi-process test 2021-06-01 08:54:19 STATE: Enumerated images: ./assets 15 2021-06-01 08:54:19 STATE: Main: started worker: 130362 2021-06-01 08:54:19 STATE: Main: started worker: 130363 2021-06-01 08:54:19 STATE: Main: started worker: 130369 2021-06-01 08:54:19 STATE: Main: started worker: 130370 2021-06-01 08:54:20 STATE: Worker: PID: 130370 TensorFlow/JS 3.6.0 Human 2.0.0 Backend: tensorflow 2021-06-01 08:54:20 STATE: Worker: PID: 130362 TensorFlow/JS 3.6.0 Human 2.0.0 Backend: tensorflow 2021-06-01 08:54:20 STATE: Worker: PID: 130369 TensorFlow/JS 3.6.0 Human 2.0.0 Backend: tensorflow 2021-06-01 08:54:20 STATE: Worker: PID: 130363 TensorFlow/JS 3.6.0 Human 2.0.0 Backend: tensorflow 2021-06-01 08:54:21 STATE: Main: dispatching to worker: 130370 2021-06-01 08:54:21 INFO: Latency: worker initializtion: 1348 message round trip: 0 2021-06-01 08:54:21 DATA: Worker received message: 130370 { test: true } 2021-06-01 08:54:21 STATE: Main: dispatching to worker: 130362 2021-06-01 08:54:21 DATA: Worker received message: 130362 { image: 'samples/ai-face.jpg' } 2021-06-01 08:54:21 DATA: Worker received message: 130370 { image: 'samples/ai-body.jpg' } 2021-06-01 08:54:21 STATE: Main: dispatching to worker: 130369 2021-06-01 08:54:21 STATE: Main: dispatching to worker: 130363 2021-06-01 08:54:21 DATA: Worker received message: 130369 { image: 'assets/human-sample-upper.jpg' } 2021-06-01 08:54:21 DATA: Worker received message: 130363 { image: 'assets/sample-me.jpg' } 2021-06-01 08:54:24 DATA: Main: worker finished: 130362 detected faces: 1 bodies: 1 hands: 0 objects: 1 2021-06-01 08:54:24 STATE: Main: dispatching to worker: 130362 2021-06-01 08:54:24 DATA: Worker received message: 130362 { image: 'assets/sample1.jpg' } 2021-06-01 08:54:25 DATA: Main: worker finished: 130369 detected faces: 1 bodies: 1 hands: 0 objects: 1 2021-06-01 08:54:25 STATE: Main: dispatching to worker: 130369 2021-06-01 08:54:25 DATA: Main: worker finished: 130370 detected faces: 1 bodies: 1 hands: 0 objects: 1 2021-06-01 08:54:25 STATE: Main: dispatching to worker: 130370 2021-06-01 08:54:25 DATA: Worker received message: 130369 { image: 'assets/sample2.jpg' } 2021-06-01 08:54:25 DATA: Main: worker finished: 130363 detected faces: 1 bodies: 1 hands: 0 objects: 2 2021-06-01 08:54:25 STATE: Main: dispatching to worker: 130363 2021-06-01 08:54:25 DATA: Worker received message: 130370 { image: 'assets/sample3.jpg' } 2021-06-01 08:54:25 DATA: Worker received message: 130363 { image: 'assets/sample4.jpg' } 2021-06-01 08:54:30 DATA: Main: worker finished: 130362 detected faces: 3 bodies: 1 hands: 0 objects: 7 2021-06-01 08:54:30 STATE: Main: dispatching to worker: 130362 2021-06-01 08:54:30 DATA: Worker received message: 130362 { image: 'assets/sample5.jpg' } 2021-06-01 08:54:31 DATA: Main: worker finished: 130369 detected faces: 3 bodies: 1 hands: 0 objects: 5 2021-06-01 08:54:31 STATE: Main: dispatching to worker: 130369 2021-06-01 08:54:31 DATA: Worker received message: 130369 { image: 'assets/sample6.jpg' } 2021-06-01 08:54:31 DATA: Main: worker finished: 130363 detected faces: 4 bodies: 1 hands: 2 objects: 2 2021-06-01 08:54:31 STATE: Main: dispatching to worker: 130363 2021-06-01 08:54:39 STATE: Main: worker exit: 130370 0 2021-06-01 08:54:39 DATA: Main: worker finished: 130362 detected faces: 1 bodies: 1 hands: 0 objects: 1 2021-06-01 08:54:39 DATA: Main: worker finished: 130369 detected faces: 1 bodies: 1 hands: 1 objects: 3 2021-06-01 08:54:39 STATE: Main: worker exit: 130362 0 2021-06-01 08:54:39 STATE: Main: worker exit: 130369 0 2021-06-01 08:54:41 DATA: Main: worker finished: 130363 detected faces: 9 bodies: 1 hands: 0 objects: 10 2021-06-01 08:54:41 STATE: Main: worker exit: 130363 0 2021-06-01 08:54:41 INFO: Processed: 15 images in total: 22006 ms working: 20658 ms average: 1377 ms ``` -------------------------------- ### WebCam Methods Source: https://github.com/vladmandic/human/blob/main/typedoc/interfaces/WebCam.html These methods allow for controlling the webcam, such as enumerating devices, pausing, playing, starting, and stopping the stream. ```APIDOC ## Methods ### enumerate * **Description**: Enumerates available video input devices. * **Returns**: `Promise` ### pause * **Description**: Pauses the webcam stream. * **Returns**: `void` ### play * **Description**: Resumes the webcam stream. * **Returns**: `Promise` ### start * **Description**: Starts the webcam stream with optional configuration. * **Parameters**: * `webcamConfig` (Partial<[WebCamConfig](WebCamConfig.html) angle) - Optional - Configuration for the webcam. * **Returns**: `Promise` ### stop * **Description**: Stops the webcam stream. * **Returns**: `void` ``` -------------------------------- ### Dockerfile for Human Web Application Source: https://github.com/vladmandic/human/wiki/Docker A Dockerfile for serving a Human web application. It sets up a NodeJS environment, installs a web server, copies necessary files, and exposes a port. ```dockerfile FROM node:16 WORKDIR RUN npm init --yes COPY build.json . RUN npm install @vladmandic/build --no-fund COPY dist ./dist COPY demo ./demo EXPOSE 10031 ENTRYPOINT node node_modules/@vladmandic/build/dist/build.js --profile serve USER node ``` -------------------------------- ### Human Configuration Reference Source: https://context7.com/vladmandic/human/llms.txt The `Config` object controls Human's behavior. All properties are optional and deep-merged over defaults. This example shows various configuration options for backend, model paths, caching, debugging, and specific detection modules like face, body, hand, object, and segmentation. ```typescript const config: Partial = { backend: 'webgl', // TF backend: 'cpu'|'wasm'|'webgl'|'humangl'|'webgpu'|'tensorflow' modelBasePath: '../models/', // base path for all model .json files cacheModels: true, // cache model weights in IndexedDB (browser only) validateModels: true, // warn on unsupported kernel ops debug: false, // verbose console output async: true, // run models in parallel (faster, more memory) warmup: 'full', // 'none'|'face'|'body'|'full' cacheSensitivity: 0.70, // scene-change threshold (0=disabled, 1=always cache) deallocate: false, // immediately free tensors (slower but lower memory) softwareKernels: false, // CPU fallback for missing GPU kernels flags: {}, // raw TF ENV flags filter: { enabled: true, flip: false, // horizontal mirror equalization: false, // histogram equalization autoBrightness:true, brightness: 0, // -1..1 contrast: 0, // -1..1 sharpness: 0, // 0..1 blur: 0, // radius in pixels saturation: 0, // -1..1 hue: 0, // 0..360 degrees negative: false, sepia: false, width: 0, // resize; 0 = no resize height: 0, }, face: { enabled: true, detector: { maxDetected: 1, minConfidence: 0.2, rotation: false, skipFrames: 99 }, mesh: { enabled: true }, iris: { enabled: true }, description: { enabled: true, minConfidence: 0.1 }, // age, gender, race, embedding emotion: { enabled: true, minConfidence: 0.1 }, antispoof: { enabled: false }, liveness: { enabled: false }, }, body: { enabled: true, modelPath: 'movenet-lightning.json', // or 'blazepose.json', 'efficientpose.json', 'posenet.json' maxDetected: -1, // -1 = auto (matches face count) minConfidence: 0.3, }, hand: { enabled: true, maxDetected: -1, // -1 = auto (2× face count) minConfidence: 0.5, landmarks: true, detector: { modelPath: 'handtrack.json' }, skeleton: { modelPath: 'handlandmark-lite.json' }, }, object: { enabled: false, modelPath: 'centernet.json', // or 'nanodet.json' maxDetected: 10, minConfidence: 0.2, }, segmentation: { enabled: false, modelPath: 'rvm.json', // or 'meet.json', 'selfie.json' ratio: 0.5, mode: 'default', // 'default'|'alpha'|'foreground'|'state' }, gesture: { enabled: true }, }; ``` -------------------------------- ### human.webcam.* Source: https://context7.com/vladmandic/human/llms.txt Provides a set of helper methods for managing webcam streams. This includes enumerating available cameras, starting and stopping streams with specific resolutions and modes, and managing the video element for display. It simplifies webcam integration into applications. ```APIDOC ## `human.webcam.*` — WebCam Helper Built-in webcam management class that handles device enumeration, stream acquisition, and lifecycle (start/stop/pause/play). ```js const human = new Human({ backend: 'webgl' }); const canvas = document.getElementById('canvas'); // Enumerate available cameras const devices = await human.webcam.enumerate(); console.log('Cameras:', devices.map((d) => d.label)); // Start front camera at 1280×720 const status = await human.webcam.start({ element: 'video-element-id', // id of an