Skip to content

Commit abcc23c

Browse files
authored
Merge pull request #21 from ml5js/handpose-example
Simplify Handpose Example
2 parents f875305 + 27526f4 commit abcc23c

File tree

3 files changed

+44
-47
lines changed

3 files changed

+44
-47
lines changed

examples/Handpose/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<script src="../../dist/ml5.js"></script>
1010
</head>
1111
<body>
12-
<script src="script.js"></script>
12+
<script src="sketch.js"></script>
1313
</body>
1414
</html>

examples/Handpose/script.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/Handpose/sketch.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
let handpose;
2+
let video;
3+
let hands = [];
4+
5+
function setup() {
6+
createCanvas(640, 480);
7+
8+
// Create the video and hide it
9+
video = createCapture(VIDEO);
10+
video.size(width, height);
11+
video.hide();
12+
13+
// Load the model and attach an event
14+
handpose = ml5.handpose(video, modelReady);
15+
handpose.on("hand", gotHands);
16+
}
17+
18+
// Event for hand detection
19+
function gotHands(results) {
20+
// Always save the latest output from the model in global variable "hands"
21+
hands = results;
22+
}
23+
24+
// Event for when model loaded
25+
function modelReady() {
26+
console.log("Model ready!");
27+
}
28+
29+
function draw() {
30+
// Draw the video
31+
image(video, 0, 0, width, height);
32+
33+
// Draw all the tracked hand points
34+
for (let i = 0; i < hands.length; i++) {
35+
let hand = hands[i];
36+
for (let j = 0; j < hand.keypoints.length; j++) {
37+
let keypoint = hand.keypoints[j];
38+
fill(0, 255, 0);
39+
noStroke();
40+
circle(keypoint.x, keypoint.y, 10);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)