-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmy_posenet.html
76 lines (66 loc) · 2.58 KB
/
my_posenet.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Getting Started with ml5.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- ml5 -->
<script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>
</head>
<body>
<script>
// Your code will go here
// open up your console - if everything loaded properly you should see 0.9.0
let video;
let poseNet;
let leftHandX = 200;
let leftHandY = 200;
function setup() {
createCanvas(800, 800);
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelReady);
poseNet.on('pose', gotPoses);
}
function gotPoses(poses) {
if (poses.length > 0) {
/*
// JSON method of logging keypoints
// For each pose, add in a timestamp for us to use
for (var i = 0; i < poses.length; i++) {
poses[i].timestamp = millis();
}
// ^ We could also do a jankier solution that has the timestamp
// appended as the last element of the poses array, to prevent
// having to iterate across each element
// Output the poses as a JSON string for extraction
console.log(JSON.stringify(poses));
*/
// Print out each of the coordinates of the first keypoint
var keypoints = poses[0].pose.keypoints
for (var i = 0; i < keypoints.length; i++) {
// Print out keypoints to console
console.log(i + ".x: " + keypoints[i].position.x)
console.log(i + ".y: " + keypoints[i].position.y)
}
console.log("Time elapsed: ", millis());
console.log("----------------------------");
// Update the left hand dot on the canvas (for debugging)
leftHandX = poses[0].pose.keypoints[9].position.x
leftHandY = poses[0].pose.keypoints[9].position.y
}
}
function modelReady() {
console.log('Model is ready.')
}
function draw() {
image(video, 0,0);
fill(200,0,0);
ellipse(leftHandX, leftHandY, 25);
}
</script>
</body>
</html>