xxxxxxxxxx
47
// p5.js + BRFv4 face tracker (via handsfree.js)
//
// We're using a specific version of handsfree.js
// that has the (commercial, trial) BRFv4 tracker baked in:
// https://unpkg.com/handsfree@4.0.3/dist/handsfree.js
// more information about the BRFv4 tracker is at:
// https://github.com/Tastenkunst/brfv4_javascript_examples
var myHandsfree;
//---------------------------------------------
function setup() {
createCanvas(640, 480);
var myConfig = {
hideCursor: true
};
myHandsfree = new Handsfree(myConfig);
myHandsfree.start();
}
//---------------------------------------------
function draw() {
background(0, 0, 0);
if (myHandsfree.isTracking) {
if (myHandsfree.pose.length > 0) {
var face0 = myHandsfree.pose[0].face;
var nDataPieces = face0.vertices.length;
fill(255, 0, 0);
for (var i = 0; i < nDataPieces; i += 2) {
var x = face0.vertices[i + 0];
var y = face0.vertices[i + 1];
ellipse(x, y, 9, 9);
}
// Rotations of the head, in radians
var rx = face0.rotationX; // pitch
var ry = face0.rotationY; // yaw
var rz = face0.rotationZ; // roll
}
}
}