-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRekognition_image_analysis.js
89 lines (84 loc) · 3.69 KB
/
Rekognition_image_analysis.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
82
83
84
85
86
87
//DaARA variable
const ACCESS_KEY_ID = "****************"
const SECRET_ACCESS_KEY = "********************************"
const REGION = "**-*********-*"
const BUCKET_NAME = "***********"
const photo_source = 'source Bucket image Name'
const photo_target = 'target Bucket image Name'
//------------------------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------------------------
//AWS config, S3
const AWS = require('aws-sdk') //AWS-SDK 모듈 사용
AWS.config.update({region:REGION});
const s3 = new AWS.S3({ // S3 Bucket authenticate
accessKeyId : ACCESS_KEY_ID,
secretAccessKey : SECRET_ACCESS_KEY,
region : REGION
});
const config = new AWS.Config({
accessKeyId: ACCESS_KEY_ID,
secretAccessKey: SECRET_ACCESS_KEY,
region: REGION
})
//------------------------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------------------------
const params = { // Bucket 안에 있는 두 개의 이미지
SourceImage: {
S3Object: {
Bucket: BUCKET_NAME,
Name: photo_source
},
},
TargetImage: {
S3Object: {
Bucket: BUCKET_NAME,
Name: photo_target
},
},
SimilarityThreshold: 95
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------------------------
client.compareFaces(params, function(err, response) { //Bucket에서 선택된 두 개의 이미지를 비교 분석
if (err) {
console.log(err, err.stack); // an error occurred
} else {
response.FaceMatches.forEach(data => {
let position = data.Face.BoundingBox
let similarity = data.Similarity
console.log(`The face at: ${position.Left}, ${position.Top} matches with ${similarity} % confidence`)
}) // for response.faceDetails
} // if
});
//------------------------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------------------------
const params_2 = { // Bucket 안에 있는 이미지 감정 분석
Image: {
S3Object: {
Bucket: BUCKET_NAME,
Name: photo_source
},
},
Attributes: ['ALL']
}
client.detectFaces(params_2, function(err, response) {
if (err) {
console.log(err, err.stack); // an error occurred
}
else {
response.FaceDetails.forEach(data => {
let low = data.AgeRange.Low
let high = data.AgeRange.High
console.log(`The detected face is between: ${low} and ${high} years old`)
console.log("All other attributes:")
console.log(` Age.Range.Low: ${data.AgeRange.Low}`)
console.log(` Age.Range.High: ${data.AgeRange.High}`)
console.log(` Smile.Value: ${data.Smile.Value}`)
console.log(` Smile.Confidence: ${data.Smile.Confidence}`)
console.log(` Emotions[0].Type: ${data.Emotions[0].Type}`)
console.log(` Emotions[0].Confidence: ${data.Emotions[0].Confidence}`)
console.log("------------")
console.log("")
}) // for response.faceDetails
} // if
});