xxxxxxxxxx
38
let video;
let poseNet;
let poses = [];
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(width, height);
// Create a new poseNet method with a single detection
poseNet = ml5.poseNet(video, modelReady);
// This sets up an event that fills the global variable "poses"
// with an array every time new poses are detected
poseNet.on('pose', function(results) {
poses = results;
});
// Hide the video element, and just show the canvas
video.hide();
}
function modelReady() {
console.log("model loaded");
//select('#status').html('Model Loaded');
}
function draw() {
image(video, 0, 0, width, height);
//console.log(poses);
if (poses && poses.length > 0) {
let x = poses[0].pose.keypoints[1].position.x;
let y = poses[0].pose.keypoints[1].position.y;
ellipse(x, y, 20, 20);
}
// We can call both functions to draw all keypoints and the skeletons
//drawKeypoints();
// drawSkeleton();
}