forked from dmarcisovska/ml5-posenet-cat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
82 lines (63 loc) · 2.45 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let video;
let poseNet;
let pose;
function meow(){
const meow = document.getElementById('meow');
meow.play();
}
function purr(){
const purr = document.getElementById('purr');
purr.play();
}
function hiss(){
const hiss = document.getElementById('hiss');
hiss.play();
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelLoaded);
poseNet.on('pose', gotPoses);
}
function gotPoses(poses) {
if (poses.length > 0) {
pose = poses[0].pose;
}
}
function modelLoaded() {
console.log('poseNet ready');
}
function draw() {
image(video, 0, 0);
if (pose) {
let eyeR = pose.rightEye;
let eyeL = pose.leftEye;
let d = dist(eyeR.x, eyeR.y, eyeL.x, eyeL.y);
//Outer Eye
fill(0);
ellipse(eyeR.x,eyeR.y,d/1.5, (d/2.5));
ellipse(eyeL.x,eyeR.y,d/1.5, d/2.5);
// Inner Eye
fill('#00ff80');
ellipse(eyeR.x - 1,eyeR.y, d/10, d/4);
ellipse(eyeL.x - 1,eyeR.y, d/10, d/4);
// Nose
fill(0);
triangle(pose.nose.x - (d/3), pose.nose.y - (d/10), pose.nose.x + (d/3), pose.nose.y -(d/10), pose.nose.x, pose.nose.y + (d/3));
//Outer Ear
triangle(pose.nose.x + d, pose.nose.y - (d*1.2), pose.nose.x + (d/1.2), pose.nose.y -(d*2), pose.nose.x + (d/5), pose.nose.y - (d*1.5));
triangle(pose.nose.x - d, pose.nose.y - (d*1.2), pose.nose.x - (d/1.2), pose.nose.y -(d*2), pose.nose.x - (d/5), pose.nose.y - (d*1.5));
// Inner Ear
fill('#FA8072');
triangle(pose.nose.x + (d*.9), pose.nose.y - (d*1.3), pose.nose.x + (d/1.3), pose.nose.y - (d*1.8), pose.nose.x + (d/3.33), pose.nose.y - (d*1.5));
triangle(pose.nose.x - (d*.9), pose.nose.y - (d*1.3), pose.nose.x - (d/1.3), pose.nose.y - (d*1.8), pose.nose.x - (d/3.33), pose.nose.y - (d*1.5));
// Whiskers
line(pose.nose.x + (d/2.5), pose.nose.y - (d/20), pose.nose.x + (d), pose.nose.y - (d/4));
line(pose.nose.x + (d/2.5), pose.nose.y + (d/20), pose.nose.x + d, pose.nose.y + (d/4));
line(pose.nose.x + (d/2.5), pose.nose.y, pose.nose.x + d, pose.nose.y);
line(pose.nose.x - (d/2.5), pose.nose.y - (d/20), pose.nose.x - d, pose.nose.y - (d/4));
line(pose.nose.x - (d/2.5), pose.nose.y + (d/20), pose.nose.x - d, pose.nose.y + (d/4));
line(pose.nose.x - (d/2.5), pose.nose.y, pose.nose.x - d, pose.nose.y);
}
}