-
Notifications
You must be signed in to change notification settings - Fork 2
/
sketch.js
53 lines (45 loc) · 1.21 KB
/
sketch.js
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
let video;
let poseNet;
let noseX = 0;
let noseY = 0;
let eyelX = 0;
let eyelY = 0;
let eyerX = 0;
let eyerY = 0;
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelReady);
poseNet.on('pose', gotPoses);
}
function gotPoses(poses) {
// console.log(poses);
if (poses.length > 0) {
let nX = poses[0].pose.keypoints[0].position.x;
let nY = poses[0].pose.keypoints[0].position.y;
let eX = poses[0].pose.keypoints[1].position.x;
let eY = poses[0].pose.keypoints[1].position.y;
let EX = poses[0].pose.keypoints[2].position.x;
let EY = poses[0].pose.keypoints[2].position.y;
noseX = lerp(noseX, nX, 0.5);
noseY = lerp(noseY, nY, 0.5);
eyelX = lerp(eyelX, eX, 0.5);
eyelY = lerp(eyelY, eY, 0.5);
eyerX = lerp(eyerX, EX, 0.5);
eyerY = lerp(eyerY, EY, 0.5);
}
}
function modelReady() {
console.log('model ready');
}
function draw() {
image(video, 0, 0);
let d = dist(noseX, noseY, eyelX, eyelY);
fill(255, 0, 0);
ellipse(noseX, noseY, d/3);
fill(0,0,255);
ellipse(eyelX, eyelY, d/3);
fill(0,0,255);
ellipse(eyerX, eyerY, d/3);
}