-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
61 lines (49 loc) · 1.46 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
let video;
let bodyPose;
let poses = [];
let connections;
function preload() {
// Load the bodyPose model
bodyPose = ml5.bodyPose();
}
function setup() {
createCanvas(640, 640);
video = createCapture(VIDEO);
video.size(500, 500);
video.hide();
bodyPose.detectStart(video, gotPoses);
connections = bodyPose.getSkeleton();
}
function gotPoses(results) {
// Store the model's results in a global variable
poses = results;
}
function draw() {
// Display the video
image(video, 0, 0, width, height);
for (let i = 0; i < poses.length; i++) {
let pose = poses[i];
for (let j = 0; j < connections.length; j++) {
let pointAIndex = connections[j][0];
let pointBIndex = connections[j][1];
let pointA = pose.keypoints[pointAIndex];
let pointB = pose.keypoints[pointBIndex];
if (pointA.confidence > 0.1 && pointB.confidence > 0.1) {
stroke(255, 0, 0);
strokeWeight(2);
line(pointA.x, pointA.y, pointB.x, pointB.y);
}
}
}
for (let i = 0; i < poses.length; i++) {
let pose = poses[i];
for (let j = 0; j < pose.keypoints.length; j++) {
let keypoint = pose.keypoints[j];
if (keypoint.confidence > 0.1) {
fill(0, 255, 0);
noStroke();
circle(keypoint.x, keypoint.y, 10);
}
}
}
}