xxxxxxxxxx
40
// This sketch is based on a sketch linked below from Yining Shi
// https://editor.p5js.org/yining/sketches/W5MU2Xc02
let bodyPose;
let video;
let poseResults;
let noseHistory = [];
let diameter = 20;
function preload() {
bodyPose = ml5.bodyPose();
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
fill(255, 0, 0);
bodyPose.detectStart(video, gotPose);
}
function gotPose(results) {
if (results && results[0]) {
poseResults = results;
const newNose = results[0].nose;
noseHistory.push(newNose);
if (noseHistory.length > 500) {
noseHistory.shift();
}
// console.log('poseResults', poseResults)
}
}
function draw() {
image(video, 0, 0, width, height);
for (let i = 0; i < noseHistory.length; i++) {
circle(noseHistory[i].x, noseHistory[i].y, diameter);
}
}