이민호

add version 1

...@@ -50,7 +50,7 @@ try { ...@@ -50,7 +50,7 @@ try {
50 * Get port from environment and store in Express. 50 * Get port from environment and store in Express.
51 */ 51 */
52 52
53 -var port = normalizePort(process.env.PORT || "8080"); 53 +var port = normalizePort(process.env.PORT || "3000");
54 app.set("port", port); 54 app.set("port", port);
55 55
56 /** 56 /**
......
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title><%= title %></title>
5 + <meta name="viewport" content="width=device-width, initial-scale=1" />
6 + <link rel="stylesheet" href="/stylesheets/main.css" />
7 + <link rel='stylesheet' href='/stylesheets/style.css' />
8 + </head>
9 + <body>
10 + <!-- <h1><%= title %></h1>
11 + <p>Welcome to <%= title %></p> -->
12 + <section class="banner full">
13 + <article>
14 + <img src="images/unknown.png" alt="" />
15 + <div class="inner">
16 + <header>
17 + <p>protect your screen from unauthorized personnel</p>
18 + <h2>AI Screensaver</h2>
19 + </header>
20 + </div>
21 + </article>
22 +
23 + </section>
24 +
25 + <section id="one" class="wrapper style2">
26 + <div class="inner">
27 + <div class="grid-style">
28 +
29 + <div>
30 + <div class="box">
31 + <div class="image fit">
32 + <img src="images/person_add.png" alt="" />
33 + </div>
34 + <div class="content">
35 + <header class="align-center">
36 + <p>add user to AWS Rekognition FaceCollection</p>
37 + <h2>Add User</h2>
38 + </header>
39 +
40 + <footer class="align-center">
41 + <form action=/register method="post" enctype="multipart/form-data">
42 + <input type="file" id="img" name="img" accept="image/png, image/jpeg" class="button alt">
43 + <input type='hidden' name="collection" id='collection' value="<%= collection %>" >
44 + <input type="text" id="image_id" name="text" placeholder="사진 이름" required><input type="submit" value="등록" class="button alt"">
45 + </form>
46 + </footer>
47 + </div>
48 + </div>
49 + </div>
50 +
51 + <div>
52 + <div class="box">
53 + <div class="image fit">
54 + <img src="images/play.png" alt="" />
55 + </div>
56 + <div class="content">
57 + <header class="align-center">
58 + <p>Detect Personnel and analyze</p>
59 + <h2>Run Detection</h2>
60 + </header>
61 + <footer class="align-center">
62 + <form action="/use" method="post">
63 + <input type="hidden" name="landing" id="landing" value="true" />
64 + <!-- <label for="type">Password (4 characters minimum):</label>
65 + <input type='password' name='type' id='type' minlength="4" required/> -->
66 + <input type='hidden' name="collection" id='collection' value="<%= collection %>" >
67 + <select name="type" id="type" class="button alt">
68 + <option value="Desktop">바탕화면</option>
69 + <option value="Logout">로그아웃</option>
70 + <option value="NewDesktop">화면전환</option>
71 + </select>
72 +
73 + <input type="submit" value="시작" class="button alt">
74 + </form>
75 + </footer>
76 + </div>
77 + </div>
78 + </div>
79 +
80 + </div>
81 + </div>
82 + </section>
83 +
84 + <script src="javascripts/jquery.min.js"></script>
85 + <script src="javascripts/jquery.scrollex.min.js"></script>
86 + <script src="javascripts/skel.min.js"></script>
87 + <script src="javascripts/util.js"></script>
88 + <script src="javascripts/main.js"></script>
89 + <script type="text/javascript">
90 + var error = '<%= error %>';
91 +
92 + if(error!='')
93 + {
94 + alert(error);
95 + }
96 +
97 +
98 + </script>
99 + </body>
100 +</html>
1 +var express = require("express");
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();
8 +
9 +const { exec } = require("child_process");
10 +
11 +router.post("/", function (req, res, next) {
12 + console.log(req.body);
13 + if (req.body.landing == "true") {
14 + res.render("use", {
15 + method: req.body.type,
16 + collection: req.body.collection,
17 + });
18 + } else {
19 + image = req.body.image;
20 + console.log(req.body.collection);
21 + // console.log(image)
22 + // var img_arr = req.body.image.split(',').map(function(item) {
23 + // return parseInt(item, 10);
24 + // });
25 + // console.log(img_arr)
26 + // enc_data = Buffer.from(image.split("data:image/png;base64,")[1], 'base64').toString('ascii')
27 + if (image[11] == "p")
28 + enc_data = atob(image.split("data:image/png;base64,")[1]);
29 + else if (image[11] == "j")
30 + enc_data = atob(image.split("data:image/jpeg;base64,")[1]);
31 + var length = enc_data.length;
32 + imageBytes = new ArrayBuffer(length);
33 + var ua = new Uint8Array(imageBytes);
34 + for (var i = 0; i < length; i++) {
35 + ua[i] = enc_data.charCodeAt(i);
36 + }
37 + // console.log(imageBytes)
38 + var params = {
39 + CollectionId: req.body.collection,
40 + FaceMatchThreshold: 95,
41 + Image: {
42 + Bytes: imageBytes,
43 + },
44 + MaxFaces: 5,
45 + };
46 + rekognition.searchFacesByImage(params, function (err, data) {
47 + if (err) {
48 + console.log(err, err.stack);
49 + } else {
50 + if (data.FaceMatches.length > 0) {
51 + res.render("redirect", {
52 + error: "Recognized!",
53 + collection: req.body.collection,
54 + });
55 + } else {
56 + exec("python action.py " + req.body.type, (error, stdout, stderr) => {
57 + if (error) {
58 + res.render("error", {
59 + message: "Error",
60 + title: "No action.py",
61 + content: "make sure you have cloned github repository",
62 + });
63 + return;
64 + }
65 + if (stderr) {
66 + res.render("error", {
67 + message: "Error",
68 + title: "No action.py",
69 + content: "make sure you have cloned github repository",
70 + });
71 + return;
72 + }
73 + console.log(`stdout: ${stdout}`);
74 + res.render("action");
75 + });
76 + }
77 + }
78 + });
79 + }
80 +});
81 +
82 +router.get("/", function (req, res, next) {
83 + res.render("use");
84 +});
85 +
86 +module.exports = router;