Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@jnv/headtrackr
Advanced tools
headtrackr is a javascript library for real-time face tracking and head tracking, tracking the position of a users head in relation to the computer screen, via a web camera and the webRTC/getUserMedia standard.
For a demonstration see this video or try out some of the examples with a laptop that has a camera and a browser that has camera webRTC/getUserMedia support. For an overview of browsers supporting the getUserMedia standard see http://caniuse.com/stream.
NB! Recent versions of Chrome only enable getUserMedia for https sites (and localhost), so make sure that live sites use https when using headtrackr.
Download the minified library headtrackr.js and include it in your webpage.
<script src="js/headtrackr.js"></script>
The following code initiates the headtrackr with a video element which will be used for the mediastream, and a canvas element we will copy the videoframes to.
<canvas id="inputCanvas" width="320" height="240" style="display:none"></canvas>
<video id="inputVideo" autoplay loop></video>
<script type="text/javascript">
var videoInput = document.getElementById('inputVideo');
var canvasInput = document.getElementById('inputCanvas');
var htracker = new headtrackr.Tracker();
htracker.init(videoInput, canvasInput);
htracker.start();
</script>
When the headtracker is started, this will now regularly generate the events headtrackingEvent and facetrackingEvent on the document. The event headtrackingEvent has the attributes x, y, z, which tells us the estimated position of the users head in relation to the center of the screen, in centimeters. The event facetrackingEvent has the attributes x, y, width, height and angle, which tell us the estimated position and size of the face on the video.
You can now either create an eventlistener to handle these events somehow, or, if you're using three.js, try to use one of the pre-packaged controllers in this library to create pseudo-3D, aka head-coupled perspective effects.
To get some more idea about usage look at the source code for the examples above, this overview, or the reference.
Make sure you have grunt and node installed.
To install the development dependencies run npm install
and to build it run grunt
in the root directory.
Headtrackr.js is distributed under the MIT License, and includes some code bits (courtesy Liu Liu and Benjamin Jung) that are under the BSD-3 License and the MIT License respectively.
FAQs
headtracking via webcam and WebRTC/getUserMedia
The npm package @jnv/headtrackr receives a total of 1 weekly downloads. As such, @jnv/headtrackr popularity was classified as not popular.
We found that @jnv/headtrackr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.