xxxxxxxxxx
116
let fps = 24;
let download = false;
let poseFrames = 0;
let data = {};
let frame = 0;
let hue = 0;
let img;
let vid;
let run = false;
function preload() {
data = loadJSON('combined.json');
img = loadImage('leaf-tx.png');
vid = createVideo(
['painted-trim.mov'],
vidLoad
);
}
function setup() {
frameRate(fps)
createCanvas(852, 480);
colorMode(HSB);
//example of pose coordinates
poseFrames = Object.keys(data).length;
//console.log(data[0][1][0]['pose_keypoints_2d'])
noStroke();
//image(img, 0, 0);
//vid.size(852, 480);
vid.hide();
}
function draw() {
//background(0,0,0,0);
image(vid, 0, 0, 852, 480);
drawPose((frameCount-1) % poseFrames)
//drawSkeleton((frameCount-1) % poseFrames)
//filter(BLUR, 6);
if(frameCount <= poseFrames && download){
save(`step${nf((frameCount-1), 4)}`);
}
}
// This function is called when the video loads
function vidLoad() {
vid.loop();
vid.volume(0);
run = true;
}
function drawPose(frame) {
//fill(hue,100,80);
let hue2 = (hue +120) % 255;
if(data[frame][1].length > 0){
let d = data[frame][1][0]['pose_keypoints_2d']
for(p = 0; p < d.length; p+=3){
if(round(d[p]) + round(d[p+1]) != 0 ){
image(img, d[p]-20, d[p+1]-20, 40, 40);
//circle(round(d[p]), round(d[p+1]), 10);
}
}
}
hue = (hue + 4) % 255;
}
function drawSkeleton(frame) {
if(data[frame][1].length > 0){
let d = data[frame][1][0]['pose_keypoints_2d']
//see for key: https://colab.research.google.com/drive/1tDSZOS3facPUYme2n48yHMeB1v86s2-Q?authuser=4#scrollTo=dJIjTRi_6ZmQ
nose = createVector(round(d[0]), round(d[1])); //0
noseExists = (nose.x + nose.y != 0) ? true : false;
chest = createVector(round(d[3]), round(d[4])); //1
chestExists = (chest.x + chest.y != 0) ? true : false;
leftShoulder = createVector(d[6], d[7]); //2
leftShoulderExists = (leftShoulder.x + leftShoulder.y != 0) ? true : false;
leftElbow = createVector(d[9], d[10]); //3
leftElbowExists = (leftElbow.x + leftElbow.y != 0) ? true : false;
leftWrist = createVector(d[12], d[13]); //3
// for(p = 0; p < d.length; p+=3){
// if(round(d[p]) + round(d[p+1]) != 0 ){
// rectMode(CENTER);
// fill(hue,100,80);
// rect(round(d[p])-13, round(d[p+1]), 30, 5)
// fill(hue2,100,80);
// rect(round(d[p])-43, round(d[p+1]), 30, 5)
// //circle(round(d[p]), round(d[p+1]), 10);
// }
// }
// print(nose)
noStroke();
fill(255);
if(noseExists) {circle(nose.x, nose.y, 5);}
if(chestExists) {circle(chest.x, chest.y, 5);}
if(leftShoulderExists) {circle(leftShoulder.x, leftShoulder.y, 5);}
if(leftElbowExists) {circle(leftElbow.x, leftElbow.y, 5);}
stroke(255);
strokeWeight(3);
if(noseExists && chestExists){ line(nose.x, nose.y, chest.x, chest.y); }
if(chestExists && leftShoulderExists){ line(chest.x, chest.y, leftShoulder.x, leftShoulder.y); }
if(leftShoulderExists && leftElbowExists){ line(leftShoulder.x, leftShoulder.y, leftElbow.x, leftElbow.y); }
// line(leftElbow.x, leftElbow.y, leftWrist.x, leftWrist.y);
}
}