-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathfaces.js
More file actions
39 lines (33 loc) · 1.15 KB
/
faces.js
File metadata and controls
39 lines (33 loc) · 1.15 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
const { getEntryMetaByKey } = require('./utils')
const getFaces = (entry, minScore) => {
const faces = getEntryMetaByKey(entry, 'faces')
if (!faces) {
return [];
}
const { width, height, data } = faces;
return data
.filter(face => face.alignedRect.score >= minScore)
.map(face => {
const { box } = face.alignedRect;
const expressions = Object.keys(face.expressions)
.map(key => { return {score: face.expressions[key], expression: key }})
.filter(v => v.score > 0.3)
.sort((a, b) => a.score - b.score < 0 ? 1 : -1)
.map(v => v.expression)
.slice(0, 2)
const gender = face.genderProbability > 0.7 ? face.gender : 'unknown';
const age = +face.age.toFixed(1);
return {
faceTag: Boolean(face.faceTag) ? face.faceTag : `${gender} (${age}y)`,
expressions,
x: +(box.x / width).toFixed(3),
y: +(box.y / height).toFixed(3),
width: +(box.width / width).toFixed(2),
height: +(box.height / height).toFixed(2),
descriptor: Object.values(face.descriptor).map(value => +(value).toFixed(4))
}
})
}
module.exports = {
getFaces
}