let video;
let posNet;
let pose;
let skeleton;
var a=0,b=0,c=0;
var rec_pose=[];
var rec_skeleton=[];
var fs=require(‘fs’)
function setup() {
createCanvas(1400, 700);
video=createCapture(VIDEO);
video.hide();
poseNet=ml5.poseNet(video,modelLoaded);
poseNet.on(‘pose’,gotPoses);
}
function modelLoaded() {
console.log(‘Model Loaded!’);
}
function gotPoses(poses)
{
//if(a==1)
//console.log(poses);
if(poses.length >0)
{
pose=poses[0].pose;
skeleton=poses[0].skeleton;
}
}
function mousePressed()
{
if(a==0)
a=1;
else if(a==1)
a=2;
}
function draw() {
background(220);
image(video,0,0);
if(pose){
// fill(0,0,255);
// ellipse(pose.nose.x,pose.nose.y,64);
for(let i=0;i<pose.keypoints.length;i++){
fill(0,255,0);
ellipse(pose.keypoints[i].position.x,pose.keypoints[i].position.y,20);
if(a==1)
{
rec_pose.push(pose.keypoints);
}
}
for(let i=0;i<skeleton.length;i++)
{
strokeWeight(5);
stroke(255);
line(skeleton[i][0].position.x,skeleton[i][0].position.y,skeleton[i][1].position.x,skeleton[i][1].position.y);
if(a==1)
{
rec_skeleton.push(skeleton);
}
}
if(a==2)
{
console.log(“POSITION”);
console.log(rec_pose);
console.log(“SKELETON”);
console.log(rec_skeleton);
fs.appendFile(“dance_rec”,rec_pose);
a=0;
}
}
}
output:-