임연수

use angularJS to visualize data

static directory change /public to /
add nodemodules angularjs
...@@ -7,11 +7,11 @@ var http = require('http'); ...@@ -7,11 +7,11 @@ var http = require('http');
7 var app= express(); 7 var app= express();
8 8
9 app.locals.pretty = true; 9 app.locals.pretty = true;
10 -app.engine('html', require('ejs').renderFile); 10 +app.use(express.static(__dirname));
11 -app.use(express.static('public'));
12 app.use('/user',express.static('uploads')); 11 app.use('/user',express.static('uploads'));
13 -app.set('views','./views'); 12 +app.set('views', __dirname + '/views');
14 app.set('view engine', 'html'); 13 app.set('view engine', 'html');
14 +app.engine('html', require('ejs').renderFile);
15 app.use(bodyParser.urlencoded({extended:false})); 15 app.use(bodyParser.urlencoded({extended:false}));
16 16
17 var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다. 17 var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다.
...@@ -25,15 +25,13 @@ var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 ...@@ -25,15 +25,13 @@ var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고
25 }); 25 });
26 var upload = multer({ storage: storage}); 26 var upload = multer({ storage: storage});
27 27
28 -
29 -
30 // Replace <Subscription Key> with your valid subscription key. 28 // Replace <Subscription Key> with your valid subscription key.
31 var subscriptionKey = '61650f4a2941462ea2dba74eabefd114'; 29 var subscriptionKey = '61650f4a2941462ea2dba74eabefd114';
32 // You must use the same location in your REST call as you used to get your 30 // You must use the same location in your REST call as you used to get your
33 // subscription keys. For example, if you got your subscription keys from 31 // subscription keys. For example, if you got your subscription keys from
34 // westus, replace "westcentralus" in the URL below with "westus". 32 // westus, replace "westcentralus" in the URL below with "westus".
35 var uriBase = 'https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect'; 33 var uriBase = 'https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect';
36 -var imageUrl = 'http://54.180.159.73:8080/user/mypic.jpg'; 34 +var imageUrl = 'http://54.180.159.73/user/mypic.jpg';
37 // Request parameters. 35 // Request parameters.
38 var params = { 36 var params = {
39 'returnFaceId': 'true', 37 'returnFaceId': 'true',
...@@ -51,13 +49,18 @@ var options = { ...@@ -51,13 +49,18 @@ var options = {
51 } 49 }
52 }; 50 };
53 51
52 +
54 app.get('/home', function(req,res){ 53 app.get('/home', function(req,res){
55 console.log("home"); 54 console.log("home");
56 res.render('upload'); 55 res.render('upload');
57 }); 56 });
57 +
58 app.post('/uploads', upload.single('userfile'),function(req,res){ 58 app.post('/uploads', upload.single('userfile'),function(req,res){
59 - res.render("facedetection") 59 + res.render("facedetection");
60 - console.log(req.file.path) 60 +
61 +});
62 +app.get('/send2api', function (req, res) {
63 + console.log("aa")
61 request.post(options, (error, response, body) => { 64 request.post(options, (error, response, body) => {
62 if (error) { 65 if (error) {
63 console.log('Error: ', error); 66 console.log('Error: ', error);
...@@ -65,9 +68,9 @@ app.post('/uploads', upload.single('userfile'),function(req,res){ ...@@ -65,9 +68,9 @@ app.post('/uploads', upload.single('userfile'),function(req,res){
65 } 68 }
66 let jsonResponse = JSON.stringify(JSON.parse(body), null, ' '); 69 let jsonResponse = JSON.stringify(JSON.parse(body), null, ' ');
67 console.log('JSON Response\n'); 70 console.log('JSON Response\n');
68 - console.log(jsonResponse); 71 + res.send(jsonResponse);
69 }); 72 });
70 -}); 73 +})
71 74
72 app.listen(8080,function(){ 75 app.listen(8080,function(){
73 console.log("connect 8080"); 76 console.log("connect 8080");
......
1 +var mainApp = angular.module('mainApp',[
2 + 'ngRoute'
3 +]);
4 +
5 +mainApp.controller('mainAdminController', ['$scope', '$http',
6 + function ($scope, $http, angularTable) {
7 + $http({
8 + method: 'GET',
9 + url: 'send2api'
10 + })
11 + .then(function (response) {
12 + $scope.data = response.data;
13 + $scope.age = response.data[0].faceAttributes.age;
14 + $scope.emotion = response.data[0].faceAttributes.emotion;
15 + $scope.gender = response.data[0].faceAttributes.gender;
16 + $scope.hair = response.data[0].faceAttributes.hair.bald;
17 + console.log(response.data[0])
18 + });
19 + }
20 +]);
...\ No newline at end of file ...\ No newline at end of file
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
20 }, 20 },
21 "homepage": "https://github.com/jun-hu/Facestimation_using_nodejs#readme", 21 "homepage": "https://github.com/jun-hu/Facestimation_using_nodejs#readme",
22 "dependencies": { 22 "dependencies": {
23 + "angular": "^1.7.5",
24 + "angular-route": "^1.7.5",
23 "body-parser": "^1.17.2", 25 "body-parser": "^1.17.2",
24 "ejs": "^2.6.1", 26 "ejs": "^2.6.1",
25 "express": "^4.15.3", 27 "express": "^4.15.3",
......

243 KB | W: | H:

427 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 -<html> 2 +<html ng-app="mainApp">
3 <head> 3 <head>
4 <title>Age Detection</title> 4 <title>Age Detection</title>
5 <meta charset="utf-8" /> 5 <meta charset="utf-8" />
6 + <script src="/node_modules/angular/angular.js"></script>
7 + <script src="/node_modules/angular-route/angular-route.js"></script>
6 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 8 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
9 + <script src="/app/app.js"></script>
10 + <style>
11 + .left-box {
12 + float: left;
13 + width: 50%;
14 + }
15 + .right-box {
16 + float: right;
17 + width: 50%;
18 + }
19 + </style>
7 </head> 20 </head>
8 -<body> 21 +<body ng-controller="mainAdminController">
9 - <img src="http://54.180.159.73:8080/user/mypic.jpg"></img> 22 + <div class="left-box">
10 - <button onclick="test()">완료</button> 23 + <img src="http://54.180.159.73:8080/user/mypic.jpg">
24 + </div>
11 25
12 -<script type="text/javascript"> 26 + <div class="right-box">
27 + <div ng-repeat="row in data">
28 + <p>age : {{ row.faceAttributes.age }}</p>
29 + <p>emotion : {{ row.faceAttributes.emotion }}</p>
30 + <p>gender : {{ row.faceAttributes.gender }}</p>
31 + <p>bald : {{ row.faceAttributes.hair.bald }}</p>
32 + </div>
13 33
14 - function test(){ 34 + </div>
15 35
16 -
17 -
18 - var params = {
19 - // Request parameters <img src="http://54.180.159.73:8080/user/mypic.jpg"></img>
20 - "returnFaceId": "true",
21 - "returnFaceLandmarks": "false",
22 - "returnFaceAttributes": "age,gender",
23 - };
24 -
25 - $.ajax({
26 - // NOTE: You must use the same location in your REST call as you used to obtain your subscription keys.
27 - // For example, if you obtained your subscription keys from westus, replace "westcentralus" in the
28 - // URL below with "westus".
29 - url: "https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect?" + $.param(params),
30 - beforeSend: function(xhrObj){
31 - // Request headers
32 - xhrObj.setRequestHeader("Content-Type","application/json");
33 -
34 - // NOTE: Replace the "Ocp-Apim-Subscription-Key" value with a valid subscription key.
35 - xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","61650f4a2941462ea2dba74eabefd114");
36 - },
37 - type: "POST",
38 -
39 -
40 - // Request body.
41 - data: '{"url":"http://localhost:8080/user/mypic.jpg"}',
42 - })
43 - .done(function(data) {
44 - alert(JSON.stringify(data));
45 - })
46 - .fail(function(data) {
47 - alert(JSON.stringify(data));
48 - });
49 - }
50 -</script>
51 </body> 36 </body>
52 </html> 37 </html>
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
18 18
19 <title>Age Detection</title> 19 <title>Age Detection</title>
20 20
21 -<link rel ="stylesheet" href="http://54.180.159.73:8080/assets/css/upload.css"> 21 +<link rel ="stylesheet" href="http://54.180.159.73:8080/public/assets/css/upload.css">
22 -<link rel="stylesheet" href="http://54.180.159.73:8080/assets/css/bootstrap.min.css"> 22 +<link rel="stylesheet" href="http://54.180.159.73:8080/public/assets/css/bootstrap.min.css">
23 -<link rel="stylesheet" href="http://54.180.159.73:8080/assets/css/animate.css"> 23 +<link rel="stylesheet" href="http://54.180.159.73:8080/public/assets/css/animate.css">
24 -<link rel="stylesheet" href="http://54.180.159.73:8080/assets/css/magnific-popup.css"> 24 +<link rel="stylesheet" href="http://54.180.159.73:8080/public/assets/css/magnific-popup.css">
25 -<link rel="stylesheet" href="http://54.180.159.73:8080/assets/css/font-awesome.min.css"> 25 +<link rel="stylesheet" href="http://54.180.159.73:8080/public/assets/css/font-awesome.min.css">
26 <!-- MAIN CSS --> 26 <!-- MAIN CSS -->
27 -<link rel="stylesheet" href="http://54.180.159.73:8080/assets/css/tooplate-style.css"> 27 +<link rel="stylesheet" href="http://54.180.159.73:8080/public/assets/css/tooplate-style.css">
28 28
29 <!-- 이 태그를 head 태그에 배치하거나 닫는 body 태그 바로 앞에 배치하세요. --> 29 <!-- 이 태그를 head 태그에 배치하거나 닫는 body 태그 바로 앞에 배치하세요. -->
30 <script src="https://apis.google.com/js/platform.js" async defer> 30 <script src="https://apis.google.com/js/platform.js" async defer>
...@@ -112,14 +112,14 @@ ...@@ -112,14 +112,14 @@
112 </footer> 112 </footer>
113 113
114 <!-- SCRIPTS --> 114 <!-- SCRIPTS -->
115 -<script src="http://54.180.159.73:8080/assets/js/jquery.js"></script> 115 +<script src="http://54.180.159.73:8080/public/assets/js/jquery.js"></script>
116 -<script src="http://54.180.159.73:8080/assets/js/bootstrap.min.js"></script> 116 +<script src="http://54.180.159.73:8080/public/assets/js/bootstrap.min.js"></script>
117 -<script src="http://54.180.159.73:8080/assets/js/jquery.parallax.js"></script> 117 +<script src="http://54.180.159.73:8080/public/assets/js/jquery.parallax.js"></script>
118 -<script src="http://54.180.159.73:8080/assets/js/smoothscroll.js"></script> 118 +<script src="http://54.180.159.73:8080/public/assets/js/smoothscroll.js"></script>
119 -<script src="http://54.180.159.73:8080/assets/js/jquery.magnific-popup.min.js"></script> 119 +<script src="http://54.180.159.73:8080/public/assets/js/jquery.magnific-popup.min.js"></script>
120 -<script src="http://54.180.159.73:8080/assets/js/magnific-popup-options.js"></script> 120 +<script src="http://54.180.159.73:8080/public/assets/js/magnific-popup-options.js"></script>
121 -<script src="http://54.180.159.73:8080/assets/js/wow.min.js"></script> 121 +<script src="http://54.180.159.73:8080/public/assets/js/wow.min.js"></script>
122 -<script src="http://54.180.159.73:8080/assets/js/custom.js"></script> 122 +<script src="http://54.180.159.73:8080/public/assets/js/custom.js"></script>
123 123
124 <script>/* 124 <script>/*
125 document.getElementById('userfile').onchange = function(){ 125 document.getElementById('userfile').onchange = function(){
......
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
96 96
97 97
98 var params = { 98 var params = {
99 - // Request parameters <img src="http://localhost:8080/user/mypic.jpg"></img> 99 + // Request parameters <img src="http://54.180.159.73:8080/user/mypic.jpg"></img>
100 "returnFaceId": "true", 100 "returnFaceId": "true",
101 "returnFaceLandmarks": "false", 101 "returnFaceLandmarks": "false",
102 "returnFaceAttributes": "age,gender", 102 "returnFaceAttributes": "age,gender",
......