Skip to content

Commit b751612

Browse files
authored
Merge pull request #15 from ml5js/model-handpose
model handpose
2 parents 9365cd9 + 5259fa0 commit b751612

File tree

7 files changed

+726
-414
lines changed

7 files changed

+726
-414
lines changed

examples/Handpose/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Document</title>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
9+
<script src="../../dist/ml5.js"></script>
10+
</head>
11+
<body>
12+
<script src="script.js"></script>
13+
</body>
14+
</html>

examples/Handpose/script.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let handpose;
2+
let video;
3+
let hands = [];
4+
5+
function setup() {
6+
createCanvas(640, 480);
7+
video = createCapture(VIDEO);
8+
video.size(width, height);
9+
10+
const options = {};
11+
handpose = ml5.handpose(video, options, modelReady);
12+
13+
// This sets up an event that fills the global variable "predictions"
14+
// with an array every time new hand poses are detected
15+
handpose.on("hand", (results) => {
16+
hands = results;
17+
});
18+
19+
// Hide the video element, and just show the canvas
20+
video.hide();
21+
}
22+
23+
function modelReady() {
24+
console.log("Model ready!");
25+
}
26+
27+
function draw() {
28+
image(video, 0, 0, width, height);
29+
30+
// We can call the drawKeypoints function to draw all keypoints
31+
32+
drawKeypoints();
33+
}
34+
35+
// A function to draw ellipses over the detected keypoints
36+
function drawKeypoints() {
37+
for (let i = 0; i < hands.length; i += 1) {
38+
const hand = hands[i];
39+
for (let j = 0; j < hand.keypoints.length; j += 1) {
40+
const keypoint = hand.keypoints[j];
41+
fill(0, 255, 0);
42+
noStroke();
43+
ellipse(keypoint.x, keypoint.y, 10, 10);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)