-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
147 lines (131 loc) · 2.69 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
let capture;
let loadedCamera;
let confidence = 0.5;
let yOff = 0;
let p = person;
let defaultWeight = 300;
let lerpRate = 0.5
function setup() {
createCanvas(windowWidth, windowHeight);
captureWebcam();
startPoseNet(capture);
}
function draw() {
let p = person;
noStroke();
yOff = (height - capture.height) / 2;
clear();
background(255);
// display video
image(capture, 0, yOff);
fill(255, 255);
rect(0, 0, width, height);
fill("red");
noStroke();
// keypoints.forEach((keypoint) => {
// circle(keypoint.position.x, keypoint.position.y + yOff, 10);
// });
makeBezier({
start: p.rightEar,
cont1: p.rightEye,
cont2: p.leftEye,
end: p.leftEar,
});
makeBezier({
start: p.rightEar,
cont1: p.rightShoulder,
cont2: p.rightElbow,
end: p.rightWrist,
});
makeBezier({
start: p.leftEar,
cont1: p.leftShoulder,
cont2: p.leftElbow,
end: p.leftWrist,
});
makeBezier({
start: p.rightWrist,
cont1: p.rightHip,
cont2: p.rightKnee,
end: p.rightAnkle,
});
makeBezier({
start: p.leftWrist,
cont1: p.leftHip,
cont2: p.leftKnee,
end: p.leftAnkle,
});
makeBezier({
start: p.leftAnkle,
cont1: p.leftKnee,
cont2: p.rightKnee,
end: p.rightAnkle,
});
}
function makeBezier({
start,
cont1,
cont2,
end,
fillColour,
strokeColour = color(0),
weight = defaultWeight,
}) {
if (fillColour !== undefined) {
fill(fillColour);
} else {
noFill();
}
if (strokeColour === null) {
noStroke();
} else {
stroke(strokeColour);
}
strokeWeight(weight);
beginShape();
vertex(start.x, start.y + yOff);
bezierVertex(
cont1.x,
cont1.y + yOff,
cont2.x,
cont2.y + yOff,
end.x,
end.y + yOff
);
endShape();
}
function captureWebcam() {
capture = createCapture(
{
audio: false,
video: {
facingMode: "user",
},
},
function (e) {
captureEvent = e;
// do things when video ready
// until then, the video element will have no dimensions, or default 640x480
setCameraDimensions();
}
);
capture.elt.setAttribute("playsinline", "");
capture.hide();
}
function setCameraDimensions() {
loadedCamera = captureEvent.getTracks()[0].getSettings();
// console.log("cameraDimensions", loadedCamera);
if (capture.width > capture.height) {
capture.size(width, (capture.height / capture.width) * width);
} else {
capture.size((capture.width / capture.height) * height, height);
}
// console.log(capture);
}
function getAngle(v0x, v0y, v1x, v1y) {
return atan2(v1y - v0y, v1x - v0x);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
setCameraDimensions();
}