seungmin lee

upload image added, random collection added

......@@ -18,6 +18,11 @@
"negotiator": "0.6.2"
}
},
"append-field": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
"integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY="
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
......@@ -84,11 +89,60 @@
"isarray": "^1.0.0"
}
},
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
"requires": {
"dicer": "0.2.5",
"readable-stream": "1.1.x"
}
},
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
},
"concat-stream": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
"requires": {
"buffer-from": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^2.2.2",
"typedarray": "^0.0.6"
},
"dependencies": {
"readable-stream": {
"version": "2.3.7",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": {
"safe-buffer": "~5.1.0"
}
}
}
},
"content-disposition": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
......@@ -118,6 +172,11 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
......@@ -136,6 +195,15 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"dicer": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
"requires": {
"readable-stream": "1.1.x",
"streamsearch": "0.1.2"
}
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
......@@ -311,6 +379,19 @@
"mime-db": "1.44.0"
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"mkdirp": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"requires": {
"minimist": "^1.2.5"
}
},
"morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
......@@ -328,11 +409,31 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"multer": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/multer/-/multer-1.4.2.tgz",
"integrity": "sha512-xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg==",
"requires": {
"append-field": "^1.0.0",
"busboy": "^0.2.11",
"concat-stream": "^1.5.2",
"mkdirp": "^0.5.1",
"object-assign": "^4.1.1",
"on-finished": "^2.3.0",
"type-is": "^1.6.4",
"xtend": "^4.0.0"
}
},
"negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
......@@ -356,6 +457,11 @@
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
},
"proxy-addr": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
......@@ -401,6 +507,24 @@
"unpipe": "1.0.0"
}
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
}
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
......@@ -457,6 +581,16 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew=="
},
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
......@@ -466,6 +600,11 @@
"mime-types": "~2.1.24"
}
},
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
......@@ -480,6 +619,11 @@
"querystring": "0.2.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
......@@ -508,6 +652,11 @@
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
}
}
}
......
......@@ -15,6 +15,7 @@
"express": "~4.16.1",
"http-errors": "^1.6.3",
"morgan": "~1.9.1",
"multer": "^1.4.2",
"python-shell": "^2.0.2"
}
}
......
......@@ -56,6 +56,8 @@ async function setupCamera() {
async function AWS_req(img_byte){
let element = document.getElementById('method');
console.log(element.value)
let collection = document.getElementById('collection');
var rekognition = new AWS.Rekognition();
var params = {
CollectionId: "6jj2",
......@@ -66,10 +68,10 @@ async function AWS_req(img_byte){
MaxFaces: 5
};
post_data = {
"result": false,
"type" : element.value,
"landing": "false",
"image":img_byte
"image":img_byte,
"collection" :collection.value
}
console.log(img_byte)
redirectPost("/use",post_data)
......
......@@ -3,9 +3,7 @@
templated.co @templatedco
Released for free under the Creative Commons Attribution 3.0 license (templated.co/license)
*/
function register_alert(){
alert("등록되었습니다.")
}
var settings = {
banner: {
......
var express = require("express");
var router = express.Router();
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var AWS = require("aws-sdk");
AWS.config.loadFromPath("./config.json");
var rekognition = new AWS.Rekognition();
/* GET home page. */
router.get("/", function (req, res, next) {
res.render("index", { title: "Express" });
var collectionID = makeid(8)
var params = {
CollectionId: collectionID
};
rekognition.createCollection(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
console.log(collectionID)
res.render("index", { title: "Express", error:"",collection: collectionID});
});
router.post("/", function (req, res, next){
console.log(req.body.collection)
res.render("index", { title: "Express", error:"",collection: req.body.collection});
});
module.exports = router;
......
......@@ -2,28 +2,53 @@ var express = require("express");
var router = express.Router();
var AWS = require("aws-sdk");
var fs = require("fs");
const path = require('path');
AWS.config.loadFromPath("./config.json");
const multer = require('multer');
var rekognition = new AWS.Rekognition();
router.post("/", (req, res) => {
var path_image = req.body.image;
var params = {};
fs.readFile(path_image, function (err, data) {
const upload = multer({
storage: multer.diskStorage({
destination(req, file, cb){
cb(null, 'uploads/')
},
filename(req, file, cb){
// 확장자 추출
const ext = path.extname(file.originalname);
// 이름설정 (basename:확장자제외 파일명) + 현재시간 + 확장자
cb(null, path.basename(file.originalname, ext) + new Date().valueOf() + ext);
},
}),
limit: { fileSize: 5 * 1024 * 1024},
});
router.post("/", upload.single('img'), (req, res) => {
console.log(req.file)
fs.readFile(req.file.path, function (err, data) {
if (err) {
console.log(err);
}
params = {
CollectionId: "6jj2",
CollectionId: req.body.collection,
DetectionAttributes: [],
ExternalImageId: req.body.text,
Image: { Bytes: data },
};
rekognition.indexFaces(params, function (err, data) {
if (err) console.log(err, err.stack);
if (err) {
console.log(err, err.stack);
res.render('redirect', {error:"not registered! is there any faces on image?",collection: req.body.collection})
}
// an error occurred
else console.log(data); // successful response
console.log("등록되었습니다.");
res.redirect("/");
fs.unlink(req.file.path, (err) => {
if (err) throw err;
console.log('image was deleted');
});
if(data.FaceRecords.length>0)
res.render('redirect', {error:"registered!",collection: req.body.collection})
else
res.render('redirect', {error:"not registered! is there any faces on image?",collection: req.body.collection})
});
});
});
......
......@@ -11,10 +11,11 @@ const { exec } = require("child_process");
router.post("/", function (req, res, next) {
console.log(req.body)
if (req.body.landing == "true") {
res.render('use', { method: req.body.type })
res.render('use', { method: req.body.type,collection:req.body.collection })
}
else {
image = req.body.image
console.log(req.body.collection)
// console.log(image)
// var img_arr = req.body.image.split(',').map(function(item) {
// return parseInt(item, 10);
......@@ -33,7 +34,7 @@ router.post("/", function (req, res, next) {
}
// console.log(imageBytes)
var params = {
CollectionId: "6jj2",
CollectionId: req.body.collection,
FaceMatchThreshold: 95,
Image: {
Bytes: imageBytes
......@@ -46,7 +47,7 @@ router.post("/", function (req, res, next) {
}
else {
if (data.FaceMatches.length>0){
res.redirect("/");
res.render("redirect", {error:"Recognized!",collection: req.body.collection });
}
else{
// todo 잠금 페이지로 이동.
......
......@@ -38,10 +38,10 @@
</header>
<footer class="align-center">
<form action=/register method="post">
<input type="file" id="image_path" name="image" accept="image/png, image/jpeg" class="button alt">
<input type="text" id="image_id" name="text" value="사진 이름""><input type="submit" value="등록" class="button alt" onclick="register_alert()">
<form action=/register method="post" enctype="multipart/form-data">
<input type="file" id="img" name="img" accept="image/png, image/jpeg" class="button alt">
<input type='hidden' name="collection" id='collection' value="<%= collection %>" >
<input type="text" id="image_id" name="text" value="사진 이름""><input type="submit" value="등록" class="button alt"">
</form>
</footer>
</div>
......@@ -63,7 +63,7 @@
<input type="hidden" name="landing" id="landing" value="true" />
<label for="type">Input Password:</label>
<input type='password' name='type' id='type'/>
<input type='hidden' name="collection" id='collection' value="<%= collection %>" >
<!-- <select name="type" id="type" class="button alt">
<option value="Desktop">바탕화면</option>
<option value="Logout">로그아웃</option>
......@@ -85,6 +85,16 @@
<script src="javascripts/jquery.scrollex.min.js"></script>
<script src="javascripts/skel.min.js"></script>
<script src="javascripts/util.js"></script>
<script src="javascripts/main.js"></script>
<script src="javascripts/main.js"></script>
<script type="text/javascript">
var error = '<%= error %>';
if(error!='')
{
alert(error);
}
</script>
</body>
</html>
......
<body>
</body>
<script type="text/javascript">
var error = '<%= error %>';
if(error!='')
{
alert(error);
}
function redirectPost(url, data) {
var form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
}
post_data = {
"collection":'<%= collection %>'
}
// window.location.href='/'
redirectPost('/',post_data)
</script>
\ No newline at end of file
......@@ -66,6 +66,7 @@ limitations under the License.
<input type="button" id="AWS_button" onclick="onClick();" value="버튼1" />
<form>
<input type="hidden" id="method" name="method" value=<%= method %> />
<input type="hidden" id="collection" name="collection" value=<%= collection %> />
</form>
</body>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
......