Skip to content

Commit cc20236

Browse files
committed
feat: commit inicial
0 parents  commit cc20236

9 files changed

+207
-0
lines changed

.env.default

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AWS_ACCESS_KEY=XXX
2+
AWS_SECRET_ACCESS_KEY=XXX
3+
AWS_REGION=XXX

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
node_modules
3+
.env

app.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const AWS = require('aws-sdk');
2+
const dotenv = require('dotenv').config();
3+
const fs = require('fs');
4+
5+
//Creación y configuración de instancia de AWS Rekognition
6+
const rekognition = new AWS.Rekognition({
7+
accessKeyId: process.env.AWS_ACCESS_KEY,
8+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
9+
region: process.env.AWS_REGION,
10+
apiVersion: '2016-06-27'
11+
});
12+
13+
//Lee la imagen, la convierte a Buffer y prepara el objeto
14+
const bitmap = fs.readFileSync('./input/imagen1.jpg');
15+
let image = {
16+
Image: {
17+
Bytes: new Buffer(bitmap)
18+
},
19+
Attributes: ['ALL']
20+
}
21+
22+
//Llama al método detectFaces
23+
rekognition.detectFaces(image, (error, data) => {
24+
if (error) {
25+
throw new Error(error);
26+
}
27+
data.FaceDetails.forEach((response) => {
28+
let maxConfidence = response.Emotions.reduce((a, b) => b.Confidence > b.Confidence ? b : a);
29+
let emotionName = '';
30+
switch (maxConfidence.Type) {
31+
case 'HAPPY':
32+
emotionName = 'ALEGRÍA';
33+
break;
34+
35+
case 'SAD':
36+
emotionName = 'PENA';
37+
break;
38+
39+
case 'ANGRY':
40+
emotionName = 'ENOJO';
41+
break;
42+
43+
case 'CONFUSED':
44+
emotionName = 'CONFUSIÓN';
45+
break;
46+
47+
case 'DISGUSTED':
48+
emotionName = 'DISGUSTO';
49+
break;
50+
51+
case 'SURPRISED':
52+
emotionName = 'SORPRESA';
53+
break;
54+
55+
case 'CALM':
56+
emotionName = 'CALMA';
57+
break;
58+
59+
case 'UNKNOWN':
60+
emotionName = 'DESCONOCIDA';
61+
break;
62+
63+
default:
64+
emotionName = 'DESCONOCIDA';
65+
break;
66+
}
67+
console.log(`La emoción predominante en la imágen es ${emotionName} con un grado de seguridad de ${maxConfidence.Confidence}`);
68+
});
69+
});

input/.empty

Whitespace-only changes.

input/imagen1.jpg

81.1 KB
Loading

input/imagen2.jpg

75.8 KB
Loading

input/imagen3.jpg

80.2 KB
Loading

package-lock.json

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "tutorial-rekognition-node",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"aws-sdk": "^2.227.1",
14+
"dotenv": "^5.0.1"
15+
}
16+
}

0 commit comments

Comments
 (0)