xxxxxxxxxx
64
let bodyPose;
let bob;
let video;
let guess="not loaded";
let poses=[];
function preload()
{
bodyPose=ml5.bodyPose("MoveNet", {flipped:true});
bob=loadImage("bob.png");
}
function showResults(result)
{
poses=result;
}
function loadComplete()
{
console.log("Classifier Loaded!");
}
function setup() {
createCanvas(640, 480);
video=createCapture(VIDEO, {flipped: true});
video.hide();
bodyPose.detectStart(video, showResults);
bob.resize(150,150);
}
function draw() {
background(220);
image(video, 0,0, width, height);
if(poses.length>0)
{
let pose=poses[0];
x= pose.nose.x;
y= pose.nose.y;
d=dist(pose.left_ear.x, pose.left_ear.y, pose.right_ear.x, pose.right_ear.y);
rise=(pose.right_ear.y-pose.nose.y);
run=(pose.right_ear.x-pose.nose.x);
a=rise/run;
a=atan(a);
//a=(a*180)/PI;
//bob.resize(d, d);
imageMode(CENTER);
scl=1.5;
push();
translate(x,y);
rotate(a);
image(bob, 0,0,d*scl ,d*scl);
pop();
imageMode(CORNER);
//circle(x,y, 20);
}
}