forked from SeoJeongmok/Snakegame_with_ml5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandpose.js
More file actions
34 lines (30 loc) · 910 Bytes
/
Handpose.js
File metadata and controls
34 lines (30 loc) · 910 Bytes
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
//https://wikidocs.net/103185
//<script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
let handpose;
let video;
let predictions = [];
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
handpose = ml5.handpose(video);
handpose.on("predict", gotResult);
}
function gotResult(results){
predictions = results;
}
function draw() {
image(video, 0, 0, width, height);
drawKeypoints();
}
function drawKeypoints() {
for (let i = 0; i < predictions.length; i += 1) {
const prediction = predictions[i]; //prediction이라는 변수에 카메라가 인식하고 있는 값을 넣기
for (let j = 0; j < prediction.landmarks.length; j += 1) { //포인트 0~20까지
const keypoint = prediction.landmarks[j];
fill(0, 255, 0);
noStroke();
ellipse(keypoint[0], keypoint[1], 10, 10); //j번째의 x, y좌표
}
}
}