-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
65 lines (56 loc) · 1.33 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
let video;
let poseNet;
let pose;
let skeleton;
function setup() {
createCanvas(windowWidth, windowHeight);
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelLoaded);
poseNet.on('pose',gotPoses);
}
function touchStarted () {
var fs = fullscreen();
if (!fs) {
fullscreen(true);
}
}
/* full screening will change the size of the canvas */
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
/* prevents the mobile browser from processing some default
* touch events */
document.ontouchmove = function(event) {
event.preventDefault();
};
function gotPoses(poses){
console.log(poses);
if(poses.length > 0){
pose = poses[0].pose;
skeleton = poses[0].skeleton;
}
}
function modelLoaded(){
console.log("model is ready");
}
function draw() {
image(video,0,0);
rectMode(CENTER);
rect(width / 2, height / 2, 200, 100);
if(pose){
for(let i =0; i <pose.keypoints.length; i++){
let x = pose.keypoints[i].position.x;
let y = pose.keypoints[i].position.y;
fill(0,255,0);
ellipse(x,y,16,16);
}
for(let i=0; i < skeleton.length; i++){
let a = skeleton[i][0];
let b = skeleton[i][1];
strokeWeight(2);
stroke(255);
line(a.position.x, a.position.y, b.position.x, b.position.y);
}
}
}