Skip to content

Commit bce4876

Browse files
committed
add handpose model
1 parent e78c371 commit bce4876

File tree

7 files changed

+745
-356
lines changed

7 files changed

+745
-356
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 = { maxHands: 2 };
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 both functions to draw all keypoints and the skeletons
31+
drawKeypoints();
32+
}
33+
34+
// A function to draw ellipses over the detected keypoints
35+
function drawKeypoints() {
36+
for (let i = 0; i < hands.length; i += 1) {
37+
const hand = hands[i];
38+
for (let j = 0; j < hand.keypoints.length; j += 1) {
39+
const keypoint = hand.keypoints[j];
40+
fill(0, 255, 0);
41+
noStroke();
42+
ellipse(keypoint.x, keypoint.y, 10, 10);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)