xxxxxxxxxx
81
var myVideoInput;
var clmFaceTracker;
var lasttop;
var lastbot;
let mouthopen;
let imgs = [];
//---------------------------------------------
function setup() {
createCanvas(640, 480);
// setup camera capture
myVideoInput = createCapture(VIDEO);
myVideoInput.size(width, height);
myVideoInput.hide();
// setup tracker
clmFaceTracker = new clm.tracker();
clmFaceTracker.init(pModel);
clmFaceTracker.start(myVideoInput.elt);
mouthopen = 0;
imgs = [];
}
//---------------------------------------------
function draw() {
image(myVideoInput, 0, 0, width, height);
// retrieve the array of face markers
var facePoints = clmFaceTracker.getCurrentPosition();
if (lasttop && lastbot && facePoints.length > 0) {
let distFace = dist(0, facePoints[7][1], 0, facePoints[33][1]);
let distMouth = dist(0, facePoints[48][1], 0, facePoints[53][1]);
if (distMouth / distFace > 0.2) {
mouthopen = 1;
let distx = dist(facePoints[44][0], 0, facePoints[50][0], 0);
let disty = dist(0, facePoints[48][1], 0, facePoints[53][1]);
let img = get(facePoints[44][0] - 20, facePoints[48][1] - 10, distx + 20, disty + 10);
//imgs.push(img);
//image(img, x1, y1, x2, y2);
const numMouths = 8;
for (let i = 0; i < numMouths; i++) {
let clampval = map(constrain(distMouth / distFace, 0.15 + i * 0.05, 0.25 + i * 2 * 0.05), 0.15, 0.25, 0, 1);
let randint1 = int(random(0, imgs.length));
let sc = map(float(i), 0, numMouths - 1, 0, 1);
push();
translate(facePoints[48][0], facePoints[48][1]);
scale(clampval * (1.0 - sc) * 0.75);
image(img, -width / 2, -height / 2, width, height);
pop();
}
/*
push();
translate(facePoints[48][0], facePoints[48][1]);
scale(clampval2*0.5);
image(imgs[randint2], -width/4, -height/4, width/2, height/2);
pop();
push();
translate(facePoints[48][0], facePoints[48][1]);
scale(clampval3*0.5);
image(imgs[randint3], -width/8, -height/8, width/4, height/4);
pop();*/
//rect(facePoints[44][0], facePoints[48][1],distx, disty);
} else {
mouthopen = 0;
}
}
if (facePoints) {
lasttop = facePoints[60];
lastbot = facePoints[57];
}
}