xxxxxxxxxx
let sora;
let video;
let handpose;
let hands;
// Font laden
function preload() {
sora = loadFont('LEMONMILK-Light.otf');
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
handpose = ml5.handpose(video, modelLoaded);
textFont(sora);
}
function draw() {
background(0, 10);
//tint(100);
//image(video, 0, 0);
if (hands && hands.length > 0) {
//fill(100, 23, 45);
tint(random(y),random(y),random(y));
stroke(100, 23, 45);
textSize(100);
textAlign(CENTER, CENTER);
// Finger tips: 4, 8, 12, 16, 20
// Finger roots: 1, 7, 9, 13, 17
// Winkel zw. 2 Punkten: Math.atan2(p2.y - p1.y, p2.x - p1.x);
push();
let a = Math.atan2(hands[0].landmarks[20][1] - hands[0].landmarks[17][1], hands[0].landmarks[20][0] - hands[0].landmarks[17][0]) + PI/2;
translate(hands[0].landmarks[20][0], hands[0].landmarks[20][1]);
rotate(a);
text("F", 0, 0);
pop();
push();
a = Math.atan2(hands[0].landmarks[16][1] - hands[0].landmarks[13][1], hands[0].landmarks[16][0] - hands[0].landmarks[13][0]) + PI/2;
translate(hands[0].landmarks[16][0], hands[0].landmarks[16][1]);
rotate(a);
text("I", 0, 0);
pop();
push();
a = Math.atan2(hands[0].landmarks[12][1] - hands[0].landmarks[9][1], hands[0].landmarks[12][0] - hands[0].landmarks[9][0]) + PI/2;
translate(hands[0].landmarks[12][0], hands[0].landmarks[12][1]);
rotate(a);
text("N", 0, 0);
pop();
// push();
// a = Math.atan2(hands[0].landmarks[8][1] - hands[0].landmarks[5][1], hands[0].landmarks[8][0] - hands[0].landmarks[5][0]) + PI/2;
// translate(hands[0].landmarks[8][0], hands[0].landmarks[8][1]);
// rotate(a);
// text("d", 0, 0);
// pop();
//thumb
push();
a = Math.atan2(hands[0].landmarks[4][1] - hands[0].landmarks[1][1], hands[0].landmarks[4][0] - hands[0].landmarks[1][0]) + PI/2;
translate(hands[0].landmarks[4][0], hands[0].landmarks[4][1]);
rotate(a);
text("D", 0, 0);
pop();
}
}
// When the model is loaded
function modelLoaded() {
console.log('Handpose loaded!');
handpose.on('predict', gotHands);
}
// Listen to new 'predict' events
function gotHands(results) {
hands = results;
}
// Listen to new 'predict' events
handpose.on('predict', results => {
predictions = results;
});