-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (60 loc) · 2.26 KB
/
script.js
File metadata and controls
73 lines (60 loc) · 2.26 KB
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
let video;
let poseNet; // This would be the machine learning model
let poses;
let emojis = [];
let neutral;
function setup() {
createCanvas(640, 480);
background(255);
video = createCapture(VIDEO);
video.hide() // hides the html element
for (let i = 0; i < 7; i++) {
emojis.push(loadImage('img/' + i.toString() + '.png'));
}
// poseNet = ml5.poseNet(video, console.log("Model Loaded"));
// poseNet.on('pose', (results) => {
// poses = results; // store the trained data into poses
// });
faceapi.load
faceapi.loadSsdMobilenetv1Model('/models')
faceapi.loadFaceExpressionModel('/models');
// console.log(faceapi.nets)
}
function draw() {
// background(0);
// image(img, x, y, w, h)
// image(video, 0, 0); // Video gives an image every frame, display at given coords
// console.log(video.elt)
faceapi.detectAllFaces(video.elt).withFaceExpressions()
.then((allFaces) => {
background(255);
image(video, 640, 0, -640, 480)
for (var detectionsWithExpressions of allFaces) {
console.log(allFaces);
let bestExpr = "";
let max = 0;
if (detectionsWithExpressions == undefined) {
console.log("No face detected");
// bestExpr = "neutral";
// max = 1;
// background(255);
// image(video, 0, 0);
}
else {
let face = detectionsWithExpressions.detection;
let exprs = detectionsWithExpressions.expressions;
for (let i = 0; i < exprs.length; i++) {
if (exprs[i].probability > max) {
max = exprs[i].probability;
bestExpr = exprs[i].expression;
bestImg = emojis[i];
}
}
let small = Math.max(face.box.width, face.box.height);
image(bestImg, face.box.x, face.box.y, small, small);
// console.log(neutral, face.box.x, face.box.y, small, small);
// co
}
}
});
}