xxxxxxxxxx
let handpose;
let video;
let predictions = [];
var camerax = 640;
var cameray = 480;
function setup() {
createCanvas(windowWidth, windowHeight);
video = createCapture(VIDEO);
video.size(camerax, cameray);
handpose = ml5.handpose(video, modelReady);
// This sets up an event that fills the global variable "predictions"
// with an array every time new hand poses are detected
handpose.on("predict", results => {
predictions = results;
});
// Hide the video element, and just show the canvas
video.hide();
background(0);
}
function modelReady() {
console.log("Model ready!");
}
function draw() {
//image(video, 0, 0, width, height);
// We can call both functions to draw all keypoints and the skeletons
drawKeypoints();
}
// A function to draw ellipses over the detected keypoints
function drawKeypoints() {
for (let i = 0; i < predictions.length; i += 1) {
const prediction = predictions[i];
for (let j = 0; j < prediction.landmarks.length; j += 1) {
const keypoint = prediction.landmarks[j];
fill(255, 20);
noStroke();
let kx = keypoint[0]/video.width * width;
let ky = keypoint[1]/video.height * height;
ellipse(kx, ky, 30, 30);
}
}
}
function keyTyped()
{
background(0);
}