xxxxxxxxxx
77
// Modified from https://gist.github.com/lmccart/2273a047874939ad8ad1
// For you to be able to share data between users
// Face tracker object
let ctracker;
let video;
function setup() {
// setup camera capture
video = createCapture(VIDEO);
video.size(400, 300);
video.hide();
// setup canvas
createCanvas(windowWidth, windowHeight);
// setup tracker
ctracker = new clm.tracker();
ctracker.init(pModel);
ctracker.start(video.elt);
noStroke();
}
function draw() {
background(255);
image(video, 0, 0);
// get array of face marker positions [x, y] format
let positions = ctracker.getCurrentPosition();
if (positions) {
// Loop through all of the positions
for (let p in positions) {
let pos = positions[p];
fill('red');
//ellipse(pos[0], pos[1], 5, 5);
fill('green');
text(p, pos[0] * 2, pos[1] * 2);
//ellipse(pos[0] * 2, pos[1] * 2, 5, 5);
}
// Calculate the distance between the 57th and 60th points of the positions array
let top = positions[60];
let bottom = positions[57];
// strokeWeight(50);
// stroke('black');
// line(top[0], top[1], bottom[0], bottom[1]);
// let d = dist(bottom[0], bottom[1], top[0], top[1]);
// console.log(d);
let a = positions[33];
let b = positions[60];
let c = positions[7];
let d = positions[11];
let e = positions[14];
fill(255);
textSize(24);
textAlign(CENTER, CENTER);
text("Look at me.", a[0], a[1]);
text("I'm not.", b[0], b[1]);
// fill(0);
// beginShape();
// vertex(a[0], a[1]);
// vertex(b[0], b[1]);
// vertex(c[0], c[1]);
// vertex(d[0], d[1]);
// vertex(e[0], e[1]);
// endShape();
}
}