xxxxxxxxxx
let light;
let regular;
let bold;
let predictions = [];
let video;
let handpose;
let hands;
// Font laden
function preload() {
//sora = loadFont('Sora-SemiBold.ttf');
light = loadFont('NunitoSans-ExtraLight.ttf');
regular = loadFont('NunitoSans-Regular.ttf');
bold = loadFont('NunitoSans-ExtraBold.ttf');
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
handpose = ml5.handpose(video, modelLoaded);
}
function draw() {
background(0);
//tint(100);
//image(video, 0, 0);
if (hands && hands.length > 0) {
// Textgröße von Abstand Daumen/ Zeigefinger
let v1 = createVector(hands[0].landmarks[4][0], hands[0].landmarks[4][1])
let v2 = createVector(hands[0].landmarks[8][0], hands[0].landmarks[8][1])
let x = (hands[0].landmarks[8][0] - hands[0].landmarks[4][0])
let y = (hands[0].landmarks[8][1] - hands[0].landmarks[4][1])
let m = Math.sqrt(x * x + y * y)
e = map(m, 0, 640, 5, 300)
if (m <= 63) {
fill(100);
textFont(light);
} else {
if (m <= 120) {
textFont(regular);
} else {
textFont(bold);
}
}
textSize(e); //textSize(e
fill(255, 255);
//stroke(255);
textAlign(CENTER, CENTER);
text("H", hands[0].landmarks[20][0], hands[0].landmarks[20][1]); //x/yKoordingatenHand
text("E", hands[0].landmarks[16][0], hands[0].landmarks[16][1]);
text("L", hands[0].landmarks[12][0], hands[0].landmarks[12][1]);
text("P", hands[0].landmarks[8][0], hands[0].landmarks[8][1]);
text("!", hands[0].landmarks[4][0], hands[0].landmarks[4][1]);
}
}
// 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;
});