xxxxxxxxxx
let capture;
let tracker;
var w = 640;
var h = 600;
let activeEmo ="🙂";
let activeFing ="";
let mode;
let fingers;
// function preload() {
// idle = loadImage('idle.png');
// Thinking =
// }
function setup() {
createCanvas(w, h)
// setup the webcam capture
capture = createCapture(VIDEO)
capture.hide()
capture.size(w,h)
// setup the face tracker
tracker = new clm.tracker()
tracker.init()
tracker.start(capture.elt)
}
function draw() {
background(255);
image(capture, 0, 0, 640 , 480);
textAlign(LEFT);
textSize(20);
text("Face hotkeys", 10, 500);
text("🙂=q 🤔=w 😂=e 😆=r 🤯=t 🥱=y", 10, 520);
text("Gestures hotkeys", 10, 550);
text(" =a 👏=s 👍=d 👎=f ✌️=g 👌=h 👋=j 👈=z 👉=x 👆=c", 10, 570);
switch (mode) {
case 0:
activeEmo="🙂"
break;
case 1:
activeEmo="🤔"
break;
case 2:
activeEmo="😂"
break;
case 3:
activeEmo="😆"
break;
case 4:
activeEmo="🤯"
break;
case 5:
activeEmo="🥱"
break;
default:
//
}
switch (fingers) {
case 0:
activeFing="👏"
break;
case 1:
activeFing="👍"
break;
case 2:
activeFing="👎"
break;
case 3:
activeFing="✌️"
break;
case 4:
activeFing="👌"
break;
case 5:
activeFing="👋"
break;
case 6:
activeFing="👈"
break;
case 7:
activeFing="👆"
break;
case 8:
activeFing="👉"
break;
case 9:
activeFing="☝️"
break;
case 10:
activeFing=""
break;
default:
//
}
// not receive the positions from the face tracker
let positions = tracker.getCurrentPosition()
textSize(230);
textAlign(CENTER,CENTER);
if(positions.length>0) {
for(var i = 0; i < positions.length; i++) {
//ellipse(positions[i][0], positions[i][1], 5, 5)
// text(i, positions[i][0], positions[i][1])
//image(activeEmo, positions[62][0], positions[1][1], 300 , 300);
text(activeEmo, positions[62][0], positions[1][1]-70);
}
}
textSize(50);
textAlign(CENTER,CENTER);
text(activeFing,mouseX,mouseY);
}
function keyPressed() {
//key for the face
if(key == 'q'){
mode = 0;
}
if(key == 'w'){
mode = 1;
}
if(key == 'e'){
mode = 2;
}
if(key == 'r'){
mode = 3;
}
if(key == 't'){
mode = 4;
}
if(key == 'y'){
mode = 5;
}
// key for the hand
if(key == 's'){
fingers = 0;
}
if(key == 'd'){
fingers = 1;
}
if(key == 'f'){
fingers = 2;
}
if(key == 'g'){
fingers = 3;
}
if(key == 'h'){
fingers = 4;
}
if(key == 'j'){
fingers = 5;
}
if(key == 'z'){
fingers = 6;
}
if(key == 'x'){
fingers = 7;
}
if(key == 'c'){
fingers = 8;
}
if(key == 'v'){
fingers = 9;
}
if(key == 'a'){
fingers = 10;
}
print(activeEmo);
}