Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

clmtrackr

> 编程语言
Open source

Javascript library for precise tracking of facial features via Constrained Local Models

6.5K stars0 likes3 views
WebsiteGitHub

About

Javascript library for precise tracking of facial features via Constrained Local Models

clmtrackr

clmtrackr is a javascript library for fitting facial models to faces in videos or images. It currently is an implementation of constrained local models fitted by regularized landmark mean-shift, as described in Jason M. Saragih's paper. clmtrackr tracks a face and outputs the coordinate positions of the face model as an array, following the numbering of the model below: Reference - Overview

The library provides some generic face models that were trained on the MUCT database and some additional self-annotated images. Check out clmtools for building your own models.

For tracking in video, it is recommended to use a browser with WebGL support, though the library should work on any modern browser.

For some more information about Constrained Local Models, take a look at Xiaoguang Yan's excellent tutorial, which was of great help in implementing this library.

Examples

  • Tracking in image
  • Tracking in video
  • Face substitution
  • Face masking
  • Realtime face deformation
  • Emotion detection
  • Caricature

Usage

Download the minified library clmtrackr.js, and include it in your webpage.

xml
/* clmtrackr libraries */
<script src="js/clmtrackr.js"></script>

The following code initiates the clmtrackr with the default model (see the reference for some alternative models), and starts the tracker running on a video element.

xml
<video id="inputVideo" width="400" height="300" autoplay loop>
  <source src="./media/somevideo.ogv" type="video/ogg"/>
</video>
<script type="text/javascript">
  var videoInput = document.getElementById('inputVideo');
  
  var ctracker = new clm.tracker();
  ctracker.init();
  ctracker.start(videoInput);
</script>

You can now get the positions of the tracked facial features as an array via getCurrentPosition():

xml
<script type="text/javascript">
  function positionLoop() {
    requestAnimationFrame(positionLoop);
    var positions = ctracker.getCurrentPosition();
    // positions = [[x_0, y_0], [x_1,y_1], ... ]
    // do something with the positions ...
  }
  positionLoop();
</script>

You can also use the built in function draw() to draw the tracked facial model on a canvas :

xml
<canvas id="drawCanvas" width="400" height="300"></canvas>
<script type="text/javascript">
  var canvasInput = document.getElementById('drawCanvas');
  var cc = canvasInput.getContext('2d');
  function drawLoop() {
    requestAnimationFrame(drawLoop);
    cc.clearRect(0, 0, canvasInput.width, canvasInput.height);
    ctracker.draw(canvasInput);
  }
  drawLoop();
</script>

See the complete example here.

Development

First, install node.js with npm.

In the root directory of clmtrackr, run npm install then run npm run build. This will create clmtrackr.js and clmtrackr.module.js in build folder.

To test the examples locally, you need to run a local server. One easy way to do this is to install http-server, a small node.js utility: npm install -g http-server. Then run http-server in the root of clmtrackr and go to https://localhost:8080/examples in your browser.

License

clmtrackr is distributed under the MIT License

Issues· 63 open

View all issuesOpen on GitHub
  • #185

    Nose slimming effect?

    Updated Sep 15, 2023
  • #182

    Bug: Image tracking on mobile gives very bad results

    Updated Sep 18, 2021
  • #184

    hide fps

    Updated Aug 16, 2021
  • #183

    High resolution error

    Updated May 24, 2021
  • #157

    My tracker doesn’t work...i can see the default model but it won't match my face ,why?

    Updated Mar 5, 2021
  • #145

    Hint: Inline Video Size is necessary

    Updated Oct 7, 2020
  • #127

    jsfeat depedency

    Updated Jun 22, 2020
  • #181

    Issue in Android Mobile

    Updated May 9, 2020
  • #153

    Increase canvas size to match video element, improve quality?

    Updated May 9, 2020
  • #162

    Is it possible to change the color of the green lines?

    Updated May 9, 2020

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 24, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言