xxxxxxxxxx
50
/*
* 👀 This is a ml5.js body pose starter for I CAN SEE YOU!
* 🔥 Learn more about the ml5.js project: https://ml5js.org/
*/
let video;
let bodyPose;
let poses = [];
function preload() {
// Load the bodyPose model
// either MoveNet or BlazePose
bodyPose = ml5.bodyPose("MoveNet");
}
// Callback function for when bodyPose outputs data
function gotPoses(results) {
// Save the output to the poses variable
poses = results;
}
function setup() {
createCanvas(640, 480);
// Create the video and hide it
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
// Start detecting poses in the webcam video
bodyPose.detectStart(video, gotPoses);
}
function draw() {
// Draw the webcam video
image(video, 0, 0, width, height);
// If we haven't detected anyone don't run anything below this line. This checks how many poses there are, if its equal to zero then there's no information about poses, so return (i.e. get outa here!)
if(poses.length === 0) return;
// we must have some detection if we got this far
// set the first pose to be a variable 'person' to make things a bit briefer from now on
let person = poses[0]
// put a circle on my nose
circle(person.nose.x, person.nose.y, 100)
}