김현기

aws rekognition으로 사진 분석 성공

Showing 1 changed file with 48 additions and 3 deletions
......@@ -13,9 +13,9 @@ var bucketName = "kindofyourdogimage";
// s3 버킷의 엔드 포인트
var bucketRegion = 'ap-northeast-2';
// access key
var accessId= 'AKIAQVXKGU466IQYEGRN';
var accessId= 'your_accessId';
// access secret key
var secretKey = '0FrMPdZR6+AkMkabAyPZWrnsVVi9EaI9/IdrWKCm';
var secretKey = 'your_secretKey';
// AWS Cognito 인증
//var identityPoolId = "ap-northeast-2:7cba9a17-588b-40d6-8c70-eb8ba4d573be";
......@@ -137,17 +137,62 @@ app.get('/form', function(req, res){
</html>
`;
res.send(output);
console.log(output);
});
// image를 받았을 때
app.post('/upload_receiver', function(req,res){
var form = new formidable.IncomingForm();
console.log(form);
const client = new AWS.Rekognition();
const params = {
"Image": {
"S3Object": {
"Bucket": bucketName,
"Name": fileName
}
},
"MaxLabels": 10,
"MinConfidence": 75
}
// 이미지 분석하기
client.detectLabels(params, function(err, response) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
console.log(`Detected labels for: ${form.name}`)
response.Labels.forEach(label => {
console.log(`Label: ${label.Name}`)
console.log(`Confidence: ${label.Confidence}`)
console.log("Instances:")
label.Instances.forEach(instance => {
let box = instance.BoundingBox
console.log(" Bounding box:")
console.log(` Top: ${box.Top}`)
console.log(` Left: ${box.Left}`)
console.log(` Width: ${box.Width}`)
console.log(` Height: ${box.Height}`)
console.log(` Confidence: ${instance.Confidence}`)
})
console.log("Parents:")
label.Parents.forEach(parent => {
console.log(` ${parent.Name}`)
})
console.log("------------")
console.log("")
}) // for response.labels
} // if
});
// S3에 upload해주기
form.parse(req, function(err, fields, files){
var s3 = new AWS.S3();
var params = {
Bucket:bucketName,
ACL:'public-read',
Key:files.userfile.namem,
Key:files.userfile.name,
Body: require('fs').createReadStream(files.userfile.path)
}
s3.upload(params, function(err, data){
......