Showing
7 changed files
with
89 additions
and
44 deletions
... | @@ -15,8 +15,8 @@ app.set("views", path.join(__dirname, "views")); | ... | @@ -15,8 +15,8 @@ app.set("views", path.join(__dirname, "views")); |
15 | app.set("view engine", "ejs"); | 15 | app.set("view engine", "ejs"); |
16 | 16 | ||
17 | app.use(logger("dev")); | 17 | app.use(logger("dev")); |
18 | -app.use(express.json()); | 18 | +app.use(express.json({limit : "50mb"})); |
19 | -app.use(express.urlencoded({ extended: true })); | 19 | +app.use(express.urlencoded({ limit:"50mb",extended: true })); |
20 | app.use(cookieParser()); | 20 | app.use(cookieParser()); |
21 | app.use(express.static(path.join(__dirname, "public"))); | 21 | app.use(express.static(path.join(__dirname, "public"))); |
22 | 22 | ... | ... |
... | @@ -23,6 +23,11 @@ | ... | @@ -23,6 +23,11 @@ |
23 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", | 23 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", |
24 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" | 24 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" |
25 | }, | 25 | }, |
26 | + "atob": { | ||
27 | + "version": "2.1.2", | ||
28 | + "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", | ||
29 | + "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" | ||
30 | + }, | ||
26 | "aws-sdk": { | 31 | "aws-sdk": { |
27 | "version": "2.791.0", | 32 | "version": "2.791.0", |
28 | "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.791.0.tgz", | 33 | "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.791.0.tgz", | ... | ... |
... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
7 | }, | 7 | }, |
8 | "dependencies": { | 8 | "dependencies": { |
9 | "@tensorflow-models/blazeface": "0.0.5", | 9 | "@tensorflow-models/blazeface": "0.0.5", |
10 | + "atob": "^2.1.2", | ||
10 | "aws-sdk": "^2.791.0", | 11 | "aws-sdk": "^2.791.0", |
11 | "cookie-parser": "~1.4.4", | 12 | "cookie-parser": "~1.4.4", |
12 | "debug": "~2.6.9", | 13 | "debug": "~2.6.9", | ... | ... |
... | @@ -65,33 +65,45 @@ async function AWS_req(img_byte){ | ... | @@ -65,33 +65,45 @@ async function AWS_req(img_byte){ |
65 | }, | 65 | }, |
66 | MaxFaces: 5 | 66 | MaxFaces: 5 |
67 | }; | 67 | }; |
68 | - rekognition.searchFacesByImage(params, function(err, data){ | ||
69 | - if (err) { | ||
70 | - console.log(err, err.stack); // an error occurred | ||
71 | - alert("AWS Not configured. Check /pubilc/javascripts/aws_setup.js"); | ||
72 | - window.location.href = '/'; | ||
73 | - } | ||
74 | - | ||
75 | - else console.log(data); // successful response | ||
76 | - if (data.FaceMatches.length>0){ | ||
77 | - post_data = { | ||
78 | - "result": true, | ||
79 | - "type" : element.value, | ||
80 | - "landing": "false" | ||
81 | - } | ||
82 | - } | ||
83 | - else{ | ||
84 | post_data = { | 68 | post_data = { |
85 | "result": false, | 69 | "result": false, |
86 | "type" : element.value, | 70 | "type" : element.value, |
87 | - "landing": "false" | 71 | + "landing": "false", |
72 | + "image":img_byte | ||
88 | } | 73 | } |
74 | + console.log(img_byte) | ||
89 | redirectPost("/use",post_data) | 75 | redirectPost("/use",post_data) |
90 | - } | 76 | + // rekognition.searchFacesByImage(params, function(err, data){ |
91 | - | 77 | + // if (err) { |
92 | - | 78 | + // console.log(err, err.stack); // an error occurred |
93 | - } | 79 | + // alert("AWS Not configured. Check /pubilc/javascripts/aws_setup.js"); |
94 | - ) | 80 | + // // window.location.href = '/'; |
81 | + // } | ||
82 | + | ||
83 | + // else console.log(data); // successful response | ||
84 | + // if (data.FaceMatches.length>0){ | ||
85 | + // post_data = { | ||
86 | + // "result": true, | ||
87 | + // "type" : element.value, | ||
88 | + // "landing": "false", | ||
89 | + // "image":img_byte | ||
90 | + // } | ||
91 | + // // redirectPost("/use",post_data) | ||
92 | + // } | ||
93 | + // else{ | ||
94 | + // post_data = { | ||
95 | + // "result": false, | ||
96 | + // "type" : element.value, | ||
97 | + // "landing": "false", | ||
98 | + // "image":img_byte | ||
99 | + // } | ||
100 | + // console.log('me!') | ||
101 | + // // redirectPost("/use",post_data) | ||
102 | + // } | ||
103 | + | ||
104 | + | ||
105 | + // } | ||
106 | + // ) | ||
95 | 107 | ||
96 | } | 108 | } |
97 | 109 | ||
... | @@ -157,7 +169,7 @@ function onClick(){ | ... | @@ -157,7 +169,7 @@ function onClick(){ |
157 | ua[i] = enc_data.charCodeAt(i); | 169 | ua[i] = enc_data.charCodeAt(i); |
158 | } | 170 | } |
159 | // console.log(ua) | 171 | // console.log(ua) |
160 | - AWS_req(ua) | 172 | + AWS_req(dataURL) |
161 | 173 | ||
162 | } | 174 | } |
163 | const setupPage = async () => { | 175 | const setupPage = async () => { | ... | ... |
1 | var express = require("express"); | 1 | var express = require("express"); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | +var AWS = require("aws-sdk"); | ||
4 | +var fs = require("fs"); | ||
5 | +var atob = require('atob'); | ||
6 | +AWS.config.loadFromPath("./config.json"); | ||
7 | +var rekognition = new AWS.Rekognition(); | ||
3 | 8 | ||
4 | const { exec } = require("child_process"); | 9 | const { exec } = require("child_process"); |
5 | 10 | ||
6 | router.post("/", function (req, res, next) { | 11 | router.post("/", function (req, res, next) { |
7 | console.log(req.body) | 12 | console.log(req.body) |
8 | - if(req.body.landing == "true"){ | 13 | + if (req.body.landing == "true") { |
9 | res.render('use', { method: req.body.type }) | 14 | res.render('use', { method: req.body.type }) |
10 | } | 15 | } |
11 | - else{ | 16 | + else { |
12 | - exec( | 17 | + image = req.body.image |
13 | - "python action.py " + | 18 | + // console.log(image) |
14 | - req.body.type, | 19 | + // var img_arr = req.body.image.split(',').map(function(item) { |
15 | - (error, stdout, stderr) => { | 20 | + // return parseInt(item, 10); |
16 | - if (error) { | 21 | + // }); |
17 | - res.render("error",{message : "Error", title:"No action.py", content:"make sure you have cloned github repository" }); | 22 | + // console.log(img_arr) |
18 | - return; | 23 | + // enc_data = Buffer.from(image.split("data:image/png;base64,")[1], 'base64').toString('ascii') |
24 | + if(image[11]=='p') | ||
25 | + enc_data = atob(image.split("data:image/png;base64,")[1]) | ||
26 | + else if(image[11]=='j') | ||
27 | + enc_data = atob(image.split("data:image/jpeg;base64,")[1]) | ||
28 | + var length = enc_data.length; | ||
29 | + imageBytes = new ArrayBuffer(length); | ||
30 | + var ua = new Uint8Array(imageBytes); | ||
31 | + for (var i = 0; i < length; i++) { | ||
32 | + ua[i] = enc_data.charCodeAt(i); | ||
33 | + } | ||
34 | + // console.log(imageBytes) | ||
35 | + var params = { | ||
36 | + CollectionId: "6jj2", | ||
37 | + FaceMatchThreshold: 95, | ||
38 | + Image: { | ||
39 | + Bytes: imageBytes | ||
40 | + }, | ||
41 | + MaxFaces: 5 | ||
42 | + }; | ||
43 | + rekognition.searchFacesByImage(params, function (err, data) { | ||
44 | + if (err) { | ||
45 | + console.log(err, err.stack); | ||
19 | } | 46 | } |
20 | - if (stderr) { | 47 | + else { |
21 | - res.render("error",{message : "Error", title:"No action.py", content:"make sure you have cloned github repository" }); | 48 | + if (data.FaceMatches.length>0){ |
22 | - return; | 49 | + res.redirect("/"); |
50 | + } | ||
51 | + else{ | ||
52 | + // todo 잠금 페이지로 이동. | ||
23 | } | 53 | } |
24 | - console.log(`stdout: ${stdout}`); | ||
25 | - res.render("action"); | ||
26 | } | 54 | } |
27 | - ); | 55 | + }); |
28 | } | 56 | } |
29 | }); | 57 | }); |
30 | 58 | ... | ... |
-
Please register or login to post a comment