xxxxxxxxxx
let sora;
let video;
let handpose;
let hands;
function preload() {
sora = loadFont('OrelegaOne-Regular.ttf');
}
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(255, 100);
stroke(255);
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("w", 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("o", 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("r", 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();
}
}
// 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;
});