added additional gestures

pull/50/head
Vladimir Mandic 2020-11-09 09:31:11 -05:00
parent 52d2bfa8da
commit 8b7c134b10
21 changed files with 71 additions and 59 deletions

BIN
assets/facemesh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -32959,11 +32959,16 @@ var rL = we((pc) => {
return [];
const t = [];
for (const e of n) {
e.annotations.rightCheek && e.annotations.leftCheek && e.annotations.rightCheek.length > 0 && e.annotations.leftCheek.length > 0 && t.push(`facing ${e.annotations.rightCheek[0][2] > 0 || e.annotations.leftCheek[0][2] < 0 ? "right" : "left"}`);
const r = Math.abs(e.mesh[374][1] - e.mesh[386][1]) / Math.abs(e.mesh[443][1] - e.mesh[450][1]);
r < 0.2 && t.push("blink left eye");
const i = Math.abs(e.mesh[145][1] - e.mesh[159][1]) / Math.abs(e.mesh[223][1] - e.mesh[230][1]);
i < 0.2 && t.push("blink right eye");
const r = e.mesh[35][2] - e.mesh[263][2];
Math.abs(r) < 10 ? t.push("facing camera") : t.push(`facing ${r < 0 ? "right" : "left"}`);
const i = Math.abs(e.mesh[374][1] - e.mesh[386][1]) / Math.abs(e.mesh[443][1] - e.mesh[450][1]);
i < 0.2 && t.push("blink left eye");
const a = Math.abs(e.mesh[145][1] - e.mesh[159][1]) / Math.abs(e.mesh[223][1] - e.mesh[230][1]);
a < 0.2 && t.push("blink right eye");
const s = Math.min(100, 500 * Math.abs(e.mesh[13][1] - e.mesh[14][1]) / Math.abs(e.mesh[10][1] - e.mesh[152][1]));
s > 10 && t.push(`mouth ${Math.trunc(s)}% open`);
const o = e.mesh[152][2];
Math.abs(o) > 10 && t.push(`head ${o < 0 ? "up" : "down"}`);
}
return t;
};
@ -33258,7 +33263,7 @@ class hG {
const l = sG.process(n, this.config);
this.perf.image = Math.trunc(ut() - e), this.analyze("Get Image:"), this.config.async ? (o = this.config.face.enabled ? this.detectFace(l.tensor) : [], this.perf.face && delete this.perf.face) : (this.state = "run:face", e = ut(), o = this.config.face.enabled ? await this.detectFace(l.tensor) : [], this.perf.face = Math.trunc(ut() - e)), this.analyze("Start Body:"), this.config.async ? (a = this.config.body.enabled ? this.models.posenet.estimatePoses(l.tensor, this.config) : [], this.perf.body && delete this.perf.body) : (this.state = "run:body", e = ut(), a = this.config.body.enabled ? await this.models.posenet.estimatePoses(l.tensor, this.config) : [], this.perf.body = Math.trunc(ut() - e)), this.analyze("End Body:"), this.analyze("Start Hand:"), this.config.async ? (s = this.config.hand.enabled ? this.models.handpose.estimateHands(l.tensor, this.config.hand) : [], this.perf.hand && delete this.perf.hand) : (this.state = "run:hand", e = ut(), s = this.config.hand.enabled ? await this.models.handpose.estimateHands(l.tensor, this.config.hand) : [], this.perf.hand = Math.trunc(ut() - e)), this.config.async && ([o, a, s] = await Promise.all([o, a, s])), l.tensor.dispose(), this.config.scoped && Kt.engine().endScope(), this.analyze("End Scope:");
let u = [];
this.config.gesture.enabled && (e = ut(), u = {body: nf.body(a), hand: nf.hand(s), face: nf.face(o)}, this.config.async ? this.perf.gesture && delete this.perf.gesture : this.perf.gesture = Math.trunc(ut() - e)), this.perf.total = Math.trunc(ut() - c), this.state = "idle", i({face: o, body: a, hand: s, gesture: u, performance: this.perf, canvas: l.canvas});
this.config.gesture.enabled && (e = ut(), u = {face: nf.face(o), body: nf.body(a), hand: nf.hand(s)}, this.config.async ? this.perf.gesture && delete this.perf.gesture : this.perf.gesture = Math.trunc(ut() - e)), this.perf.total = Math.trunc(ut() - c), this.state = "idle", i({face: o, body: a, hand: s, gesture: u, performance: this.perf, canvas: l.canvas});
});
}
}

File diff suppressed because one or more lines are too long

View File

@ -23,7 +23,7 @@
"imports": []
},
"dist/human.esm.js": {
"bytes": 1278518,
"bytes": 1278633,
"imports": []
}
},
@ -31,13 +31,13 @@
"dist/demo-browser-index.js.map": {
"imports": [],
"inputs": {},
"bytes": 5534714
"bytes": 5535482
},
"dist/demo-browser-index.js": {
"imports": [],
"inputs": {
"dist/human.esm.js": {
"bytesInOutput": 1664968
"bytesInOutput": 1665139
},
"dist/human.esm.js": {
"bytesInOutput": 8716
@ -52,7 +52,7 @@
"bytesInOutput": 16209
}
},
"bytes": 1712336
"bytes": 1712507
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -194,7 +194,7 @@
]
},
"src/gesture.js": {
"bytes": 2680,
"bytes": 3233,
"imports": []
},
"src/hand/anchors.js": {
@ -301,7 +301,7 @@
"dist/human.esm-nobundle.js.map": {
"imports": [],
"inputs": {},
"bytes": 620981
"bytes": 621753
},
"dist/human.esm-nobundle.js": {
"imports": [],
@ -394,7 +394,7 @@
"bytesInOutput": 1219
},
"src/gesture.js": {
"bytesInOutput": 1459
"bytesInOutput": 1574
},
"src/imagefx.js": {
"bytesInOutput": 11013
@ -415,7 +415,7 @@
"bytesInOutput": 0
}
},
"bytes": 216844
"bytes": 216959
}
}
}

4
dist/human.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

8
dist/human.esm.json vendored
View File

@ -371,7 +371,7 @@
]
},
"src/gesture.js": {
"bytes": 2680,
"bytes": 3233,
"imports": []
},
"src/hand/anchors.js": {
@ -513,7 +513,7 @@
"dist/human.esm.js.map": {
"imports": [],
"inputs": {},
"bytes": 5416966
"bytes": 5417738
},
"dist/human.esm.js": {
"imports": [],
@ -663,7 +663,7 @@
"bytesInOutput": 1197
},
"src/gesture.js": {
"bytesInOutput": 1460
"bytesInOutput": 1575
},
"src/imagefx.js": {
"bytesInOutput": 11014
@ -684,7 +684,7 @@
"bytesInOutput": 0
}
},
"bytes": 1278518
"bytes": 1278633
}
}
}

4
dist/human.js vendored

File diff suppressed because one or more lines are too long

4
dist/human.js.map vendored

File diff suppressed because one or more lines are too long

8
dist/human.json vendored
View File

@ -371,7 +371,7 @@
]
},
"src/gesture.js": {
"bytes": 2680,
"bytes": 3233,
"imports": []
},
"src/hand/anchors.js": {
@ -513,7 +513,7 @@
"dist/human.js.map": {
"imports": [],
"inputs": {},
"bytes": 5416962
"bytes": 5417734
},
"dist/human.js": {
"imports": [],
@ -663,7 +663,7 @@
"bytesInOutput": 1197
},
"src/gesture.js": {
"bytesInOutput": 1460
"bytesInOutput": 1575
},
"src/imagefx.js": {
"bytesInOutput": 11014
@ -681,7 +681,7 @@
"bytesInOutput": 7312
}
},
"bytes": 1278563
"bytes": 1278678
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/human.node.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -194,7 +194,7 @@
]
},
"src/gesture.js": {
"bytes": 2680,
"bytes": 3233,
"imports": []
},
"src/hand/anchors.js": {
@ -301,7 +301,7 @@
"dist/human.node-nobundle.js.map": {
"imports": [],
"inputs": {},
"bytes": 635158
"bytes": 635930
},
"dist/human.node-nobundle.js": {
"imports": [],
@ -394,7 +394,7 @@
"bytesInOutput": 1219
},
"src/gesture.js": {
"bytesInOutput": 1459
"bytesInOutput": 1574
},
"src/imagefx.js": {
"bytesInOutput": 11013
@ -415,7 +415,7 @@
"bytesInOutput": 7256
}
},
"bytes": 216851
"bytes": 216966
}
}
}

View File

@ -22,13 +22,20 @@ exports.face = (res) => {
if (!res) return [];
const gestures = [];
for (const face of res) {
if (face.annotations['rightCheek'] && face.annotations['leftCheek'] && (face.annotations['rightCheek'].length > 0) && (face.annotations['leftCheek'].length > 0)) {
gestures.push(`facing ${((face.annotations['rightCheek'][0][2] > 0) || (face.annotations['leftCheek'][0][2] < 0)) ? 'right' : 'left'}`);
}
// if (face.annotations['rightCheek'] && face.annotations['leftCheek'] && (face.annotations['rightCheek'].length > 0) && (face.annotations['leftCheek'].length > 0)) {
// gestures.push(`facing ${((face.annotations['rightCheek'][0][2] > 0) || (face.annotations['leftCheek'][0][2] < 0)) ? 'right' : 'left'}`);
// }
const eyeFacing = face.mesh[35][2] - face.mesh[263][2];
if (Math.abs(eyeFacing) < 10) gestures.push('facing camera');
else gestures.push(`facing ${eyeFacing < 0 ? 'right' : 'left'}`);
const openLeft = Math.abs(face.mesh[374][1] - face.mesh[386][1]) / Math.abs(face.mesh[443][1] - face.mesh[450][1]); // center of eye inner lid y coord div center of wider eye border y coord
if (openLeft < 0.2) gestures.push('blink left eye');
const openRight = Math.abs(face.mesh[145][1] - face.mesh[159][1]) / Math.abs(face.mesh[223][1] - face.mesh[230][1]); // center of eye inner lid y coord div center of wider eye border y coord
if (openRight < 0.2) gestures.push('blink right eye');
const mouthOpen = Math.min(100, 500 * Math.abs(face.mesh[13][1] - face.mesh[14][1]) / Math.abs(face.mesh[10][1] - face.mesh[152][1]));
if (mouthOpen > 10) gestures.push(`mouth ${Math.trunc(mouthOpen)}% open`);
const chinDepth = face.mesh[152][2];
if (Math.abs(chinDepth) > 10) gestures.push(`head ${chinDepth < 0 ? 'up' : 'down'}`);
}
return gestures;
};

View File

@ -363,7 +363,7 @@ class Human {
let gestureRes = [];
if (this.config.gesture.enabled) {
timeStamp = now();
gestureRes = { body: gesture.body(poseRes), hand: gesture.hand(handRes), face: gesture.face(faceRes) };
gestureRes = { face: gesture.face(faceRes), body: gesture.body(poseRes), hand: gesture.hand(handRes) };
if (!this.config.async) this.perf.gesture = Math.trunc(now() - timeStamp);
else if (this.perf.gesture) delete this.perf.gesture;
}

2
wiki

@ -1 +1 @@
Subproject commit 63c2347b5256777d5154bd5d502b2a075d3d950d
Subproject commit 17d21d19953ab16616c4a07423c0eada76577686