xxxxxxxxxx
let sora;
let video;
let handpose;
let hands;
let sound;
let amplitude;
let peaks;
let index = 0;
// Font laden
function preload() {
sora = loadFont('Sora-SemiBold.ttf');
video = createVideo("F-Akkord.mp4", videoloaded);
video.hide();
video.loop();
handpose = ml5.handpose(video, modelLoaded);
//sound = loadSound("Ukulele_smallfile.mp3");
}
function videoloaded() {
//handpose = ml5.handpose(video, modelLoaded);
//video.loop();
}
function setup() {
createCanvas(550, 360);
//video = createCapture(VIDEO);
amplitude = new p5.Amplitude();
amplitude.setInput(video); // set video as imput
textFont(sora);
// array to save amplitudes
peaks = [0];
}
function draw() {
background(150, 100);
//tint(112, 100, 150);
image(video, 0, 0);
let level = amplitude.getLevel();
//text(level, 20, 20);
//rect(width/2, height/2, level*100, level*100);
let peak = map(level, 0, 0.5, 0, 500);
peaks.push(peak); // add peak to array
if (peaks.length > width/2)
peaks.shift(); // remove last element
// draw peaks
for (let i = 0; i < peaks.length; i++) {
stroke(255);
line(i, height, i, height-peaks[i]);
}
if (hands && hands.length > 0) {
text(hands.length, 20, 20);
fill(255, 20, 147, );
stroke(500);
textSize(90);
textAlign(CENTER, BOTTOM);
// Finger tips: 4, 8, 12, 16, 20
//text(".", hands[0].landmarks[20][0], hands[0].landmarks[20][1]);
//text(".", hands[0].landmarks[16][0], hands[0].landmarks[16][1]);
text(".", hands[0].landmarks[12][0], hands[0].landmarks[12][1]);
text(".", 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;
});