xxxxxxxxxx
let sora;
let video;
let handpose;
let hands;
// Font laden
function preload() {
sora = loadFont('Sora-SemiBold.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(239, 118, 122, 100);
image(video, 0, 0);
filter(INVERT);
if (hands && hands.length > 0) {
fill(69, 105, 144);
textSize(100);
textAlign(CENTER, TOP);
// Finger tips: 4, 8, 12, 16, 20
text("S", hands[0].landmarks[20][0], hands[0].landmarks[20][1]);
text("T", hands[0].landmarks[16][0], hands[0].landmarks[16][1]);
text("E", 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;
});