xxxxxxxxxx
let video;
let poseNet;
let poses = [];
function preload() {
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
poseNet = ml5.poseNet(video, modelLoaded);
poseNet.on("pose", function(results) {
poses = results;
});
}
function draw() {
background(0);
tint(100);
image(video, 0, 0);
// Draw all joints
fill(255, 0, 100, 100);
stroke(255);
drawKeypoints();
if (poses.length > 0) {
//fill(255, 0, 100, 100);
//stroke(255);
//let pose = poses[0].pose;
//ellipse(pose.leftShoulder.x, pose.leftShoulder.y-10, 20, 20);
}
}
function mousePressed() {
}
function modelLoaded() {
print("Model Loaded");
}
// A function to draw ellipses over the detected keypoints
function drawKeypoints() {
// Loop through all the poses detected
for (let i = 0; i < poses.length; i += 1) {
// For each pose detected, loop through all the keypoints
const pose = poses[i].pose;
for (let j = 0; j < pose.keypoints.length; j += 1) {
// A keypoint is an object describing a body part (like rightArm or leftShoulder)
const keypoint = pose.keypoints[j];
// Only draw an ellipse is the pose probability is bigger than 0.2
if (keypoint.score > 0.2) {
//noFill();
//stroke(200);
ellipse(keypoint.position.x, keypoint.position.y, 5, 5);
}
}
}
}