박선진

1. 응답으로 디텍션=true 받은 경우 해당 프레임 데이터를 이미지로 저장

2. save image api 추가(방문자 사진 업로드 기능)
...@@ -4,8 +4,6 @@ const ffmpeg = require('ffmpeg'); ...@@ -4,8 +4,6 @@ const ffmpeg = require('ffmpeg');
4 const request = require('request') 4 const request = require('request')
5 5
6 const router = express.Router(); 6 const router = express.Router();
7 -const path = require('path');
8 -//================================================================
9 7
10 router.post('/videoResult', function (req, res) { 8 router.post('/videoResult', function (req, res) {
11 9
...@@ -15,7 +13,6 @@ router.post('/videoResult', function (req, res) { ...@@ -15,7 +13,6 @@ router.post('/videoResult', function (req, res) {
15 str = preview.replace(/^data:(.*?);base64,/, ""); 13 str = preview.replace(/^data:(.*?);base64,/, "");
16 str = str.replace(/ /g, '+'); 14 str = str.replace(/ /g, '+');
17 15
18 -
19 fs.writeFileSync(`./data/temp.mp4`, str, 'base64', function (err) { 16 fs.writeFileSync(`./data/temp.mp4`, str, 'base64', function (err) {
20 if (err) throw err; 17 if (err) throw err;
21 console.log("video saved"); 18 console.log("video saved");
...@@ -24,8 +21,6 @@ router.post('/videoResult', function (req, res) { ...@@ -24,8 +21,6 @@ router.post('/videoResult', function (req, res) {
24 21
25 let process = new ffmpeg(`./data/temp.mp4`); 22 let process = new ffmpeg(`./data/temp.mp4`);
26 23
27 -
28 - detectedImgFile = "test.jpg"; // null로 바꿀 것
29 process.then(function (video) { 24 process.then(function (video) {
30 video.fnExtractFrameToJPG(__dirname + "/data", 25 video.fnExtractFrameToJPG(__dirname + "/data",
31 { 26 {
...@@ -33,31 +28,26 @@ router.post('/videoResult', function (req, res) { ...@@ -33,31 +28,26 @@ router.post('/videoResult', function (req, res) {
33 file_name: 'frame_%s' 28 file_name: 'frame_%s'
34 }, function (error, files) { 29 }, function (error, files) {
35 if (!error) 30 if (!error)
36 - console.log('###1 Frames =>' + files);
37 - console.log("###2 갯수 => " + files.length)
38 -
39 -
40 - console.log("###3 첫번째 파일 => " + files[0]); // 마지막 파일은 영상임
41 - let base64str = base64_encode(files[0]);
42 - console.log("###4 base64str => " + base64str);
43 - console.log("##### for")
44 for(var i=0;i<files.length-1;i++){ 31 for(var i=0;i<files.length-1;i++){
32 + let base64str = base64_encode(files[i]);
45 request.post({ 33 request.post({
46 url: 'http://101.101.210.73/process', 34 url: 'http://101.101.210.73/process',
47 form: { 35 form: {
48 - 'data': base64_encode(files[0]) 36 + 'data': base64str,
37 + 'index': i
49 }, 38 },
50 json: true 39 json: true
51 }, (err, response, body) => { 40 }, (err, response, body) => {
52 console.log(body) 41 console.log(body)
42 + var index=body['index'];
43 + if(body['unknown_person'] == true){
44 + save_Result_image((files[index]), 'unknown', index);
45 + }
46 + if(body['fire_broken'] == true){
47 + save_Result_image((files[index]), 'fire', index);
48 + }
53 }) 49 })
54 } 50 }
55 - /**
56 - * TODO
57 - * 반복문돌면서 각 프레임 파이썬 api 요청하고 응답받아서
58 - * 하나라도 true나오면 프론트에 감지된 이미지파일주소 응답
59 - */
60 - detectedImgFile=null;
61 } 51 }
62 ) 52 )
63 }) 53 })
...@@ -66,7 +56,28 @@ router.post('/videoResult', function (req, res) { ...@@ -66,7 +56,28 @@ router.post('/videoResult', function (req, res) {
66 console.error(err); 56 console.error(err);
67 } 57 }
68 58
69 - return res.json({ data: detectedImgFile }); 59 + return res.json({ data: true });
60 +});
61 +
62 +router.post('/saveImage', function (req, res) {
63 + try {
64 + let preview = req.body[0].preview;
65 + str = preview.replace(/^data:(.*?);base64,/, "");
66 + base64str = str.replace(/ /g, '+');
67 + request.post({
68 + url: 'http://101.101.210.73/save',
69 + form: {
70 + 'data': base64str,
71 + 'name': 'temp'
72 + },
73 + json: true
74 + }, (err, response, body) => {
75 + console.log(body);
76 + })
77 + } catch (err) {
78 + console.error(err);
79 + }
80 + return res.json({ data: true });
70 }); 81 });
71 82
72 function base64_encode(file) { 83 function base64_encode(file) {
...@@ -76,4 +87,12 @@ function base64_encode(file) { ...@@ -76,4 +87,12 @@ function base64_encode(file) {
76 return new Buffer(bitmap).toString('base64'); 87 return new Buffer(bitmap).toString('base64');
77 } 88 }
78 89
90 +function save_Result_image(file, type, index){
91 + var bitmap = fs.readFileSync(file);
92 + var filePath = './' + type + '/' + index + '.jpg';
93 + fs.writeFile(filePath, bitmap, function(err){
94 + console.log('save');
95 + });
96 +}
97 +
79 module.exports = router; 98 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
No preview for this file type
...@@ -4,11 +4,31 @@ ...@@ -4,11 +4,31 @@
4 "lockfileVersion": 1, 4 "lockfileVersion": 1,
5 "requires": true, 5 "requires": true,
6 "dependencies": { 6 "dependencies": {
7 + "@types/concat-stream": {
8 + "version": "1.6.0",
9 + "resolved": "https://registry.npmjs.org/@types/concat-stream/-/concat-stream-1.6.0.tgz",
10 + "integrity": "sha1-OU2+C7X+5Gs42JZzXoto7yOQ0A0=",
11 + "requires": {
12 + "@types/node": "*"
13 + }
14 + },
15 + "@types/form-data": {
16 + "version": "0.0.33",
17 + "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-0.0.33.tgz",
18 + "integrity": "sha1-yayFsqX9GENbjIXZ7LUObWyJP/g=",
19 + "requires": {
20 + "@types/node": "*"
21 + }
22 + },
7 "@types/node": { 23 "@types/node": {
8 "version": "14.0.14", 24 "version": "14.0.14",
9 "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz", 25 "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz",
10 - "integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ==", 26 + "integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ=="
11 - "optional": true 27 + },
28 + "@types/qs": {
29 + "version": "6.9.3",
30 + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.3.tgz",
31 + "integrity": "sha512-7s9EQWupR1fTc2pSMtXRQ9w9gLOcrJn+h7HOXw4evxyvVqMi4f+q7d2tnFe3ng3SNHjtK+0EzGMGFUQX4/AQRA=="
12 }, 32 },
13 "accepts": { 33 "accepts": {
14 "version": "1.3.7", 34 "version": "1.3.7",
...@@ -54,6 +74,11 @@ ...@@ -54,6 +74,11 @@
54 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 74 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
55 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 75 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
56 }, 76 },
77 + "asap": {
78 + "version": "2.0.6",
79 + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
80 + "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
81 + },
57 "asn1": { 82 "asn1": {
58 "version": "0.2.4", 83 "version": "0.2.4",
59 "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", 84 "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
...@@ -107,6 +132,11 @@ ...@@ -107,6 +132,11 @@
107 "type-is": "~1.6.17" 132 "type-is": "~1.6.17"
108 } 133 }
109 }, 134 },
135 + "buffer-from": {
136 + "version": "1.1.1",
137 + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
138 + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
139 + },
110 "bytes": { 140 "bytes": {
111 "version": "3.1.0", 141 "version": "3.1.0",
112 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 142 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
...@@ -130,6 +160,17 @@ ...@@ -130,6 +160,17 @@
130 "delayed-stream": "~1.0.0" 160 "delayed-stream": "~1.0.0"
131 } 161 }
132 }, 162 },
163 + "concat-stream": {
164 + "version": "1.6.2",
165 + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
166 + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
167 + "requires": {
168 + "buffer-from": "^1.0.0",
169 + "inherits": "^2.0.3",
170 + "readable-stream": "^2.2.2",
171 + "typedarray": "^0.0.6"
172 + }
173 + },
133 "console-control-strings": { 174 "console-control-strings": {
134 "version": "1.1.0", 175 "version": "1.1.0",
135 "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", 176 "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
...@@ -341,6 +382,11 @@ ...@@ -341,6 +382,11 @@
341 "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 382 "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
342 "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 383 "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
343 }, 384 },
385 + "fs": {
386 + "version": "0.0.1-security",
387 + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
388 + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
389 + },
344 "gauge": { 390 "gauge": {
345 "version": "2.7.4", 391 "version": "2.7.4",
346 "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", 392 "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
...@@ -356,6 +402,11 @@ ...@@ -356,6 +402,11 @@
356 "wide-align": "^1.1.0" 402 "wide-align": "^1.1.0"
357 } 403 }
358 }, 404 },
405 + "get-port": {
406 + "version": "3.2.0",
407 + "resolved": "https://registry.npmjs.org/get-port/-/get-port-3.2.0.tgz",
408 + "integrity": "sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw="
409 + },
359 "getpass": { 410 "getpass": {
360 "version": "0.1.7", 411 "version": "0.1.7",
361 "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", 412 "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
...@@ -383,6 +434,17 @@ ...@@ -383,6 +434,17 @@
383 "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", 434 "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
384 "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" 435 "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
385 }, 436 },
437 + "http-basic": {
438 + "version": "8.1.3",
439 + "resolved": "https://registry.npmjs.org/http-basic/-/http-basic-8.1.3.tgz",
440 + "integrity": "sha512-/EcDMwJZh3mABI2NhGfHOGOeOZITqfkEO4p/xK+l3NpyncIHUQBoMvCSF/b5GqvKtySC2srL/GGG3+EtlqlmCw==",
441 + "requires": {
442 + "caseless": "^0.12.0",
443 + "concat-stream": "^1.6.2",
444 + "http-response-object": "^3.0.1",
445 + "parse-cache-control": "^1.0.1"
446 + }
447 + },
386 "http-errors": { 448 "http-errors": {
387 "version": "1.7.2", 449 "version": "1.7.2",
388 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", 450 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
...@@ -395,6 +457,21 @@ ...@@ -395,6 +457,21 @@
395 "toidentifier": "1.0.0" 457 "toidentifier": "1.0.0"
396 } 458 }
397 }, 459 },
460 + "http-response-object": {
461 + "version": "3.0.2",
462 + "resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz",
463 + "integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==",
464 + "requires": {
465 + "@types/node": "^10.0.3"
466 + },
467 + "dependencies": {
468 + "@types/node": {
469 + "version": "10.17.26",
470 + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.26.tgz",
471 + "integrity": "sha512-myMwkO2Cr82kirHY8uknNRHEVtn0wV3DTQfkrjx17jmkstDRZ24gNUdl8AHXVyVclTYI/bNjgTPTAWvWLqXqkw=="
472 + }
473 + }
474 + },
398 "http-signature": { 475 "http-signature": {
399 "version": "1.2.0", 476 "version": "1.2.0",
400 "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", 477 "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
...@@ -533,6 +610,11 @@ ...@@ -533,6 +610,11 @@
533 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 610 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
534 "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" 611 "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
535 }, 612 },
613 + "node-fetch": {
614 + "version": "2.6.0",
615 + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
616 + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
617 + },
536 "npmlog": { 618 "npmlog": {
537 "version": "4.1.2", 619 "version": "4.1.2",
538 "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", 620 "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
...@@ -587,6 +669,11 @@ ...@@ -587,6 +669,11 @@
587 "opencv-build": "^0.1.9" 669 "opencv-build": "^0.1.9"
588 } 670 }
589 }, 671 },
672 + "parse-cache-control": {
673 + "version": "1.0.1",
674 + "resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz",
675 + "integrity": "sha1-juqz5U+laSD+Fro493+iGqzC104="
676 + },
590 "parseurl": { 677 "parseurl": {
591 "version": "1.3.3", 678 "version": "1.3.3",
592 "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 679 "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
...@@ -621,6 +708,14 @@ ...@@ -621,6 +708,14 @@
621 "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", 708 "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
622 "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" 709 "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
623 }, 710 },
711 + "promise": {
712 + "version": "8.1.0",
713 + "resolved": "https://registry.npmjs.org/promise/-/promise-8.1.0.tgz",
714 + "integrity": "sha512-W04AqnILOL/sPRXziNicCjSNRruLAuIHEOVBazepu0545DDNGYHz7ar9ZgZ1fMU8/MA4mVxp5rkBWRi6OXIy3Q==",
715 + "requires": {
716 + "asap": "~2.0.6"
717 + }
718 + },
624 "proxy-addr": { 719 "proxy-addr": {
625 "version": "2.0.6", 720 "version": "2.0.6",
626 "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", 721 "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
...@@ -819,6 +914,49 @@ ...@@ -819,6 +914,49 @@
819 "ansi-regex": "^2.0.0" 914 "ansi-regex": "^2.0.0"
820 } 915 }
821 }, 916 },
917 + "sync-request": {
918 + "version": "6.1.0",
919 + "resolved": "https://registry.npmjs.org/sync-request/-/sync-request-6.1.0.tgz",
920 + "integrity": "sha512-8fjNkrNlNCrVc/av+Jn+xxqfCjYaBoHqCsDz6mt030UMxJGr+GSfCV1dQt2gRtlL63+VPidwDVLr7V2OcTSdRw==",
921 + "requires": {
922 + "http-response-object": "^3.0.1",
923 + "sync-rpc": "^1.2.1",
924 + "then-request": "^6.0.0"
925 + }
926 + },
927 + "sync-rpc": {
928 + "version": "1.3.6",
929 + "resolved": "https://registry.npmjs.org/sync-rpc/-/sync-rpc-1.3.6.tgz",
930 + "integrity": "sha512-J8jTXuZzRlvU7HemDgHi3pGnh/rkoqR/OZSjhTyyZrEkkYQbk7Z33AXp37mkPfPpfdOuj7Ex3H/TJM1z48uPQw==",
931 + "requires": {
932 + "get-port": "^3.1.0"
933 + }
934 + },
935 + "then-request": {
936 + "version": "6.0.2",
937 + "resolved": "https://registry.npmjs.org/then-request/-/then-request-6.0.2.tgz",
938 + "integrity": "sha512-3ZBiG7JvP3wbDzA9iNY5zJQcHL4jn/0BWtXIkagfz7QgOL/LqjCEOBQuJNZfu0XYnv5JhKh+cDxCPM4ILrqruA==",
939 + "requires": {
940 + "@types/concat-stream": "^1.6.0",
941 + "@types/form-data": "0.0.33",
942 + "@types/node": "^8.0.0",
943 + "@types/qs": "^6.2.31",
944 + "caseless": "~0.12.0",
945 + "concat-stream": "^1.6.0",
946 + "form-data": "^2.2.0",
947 + "http-basic": "^8.1.1",
948 + "http-response-object": "^3.0.1",
949 + "promise": "^8.0.0",
950 + "qs": "^6.4.0"
951 + },
952 + "dependencies": {
953 + "@types/node": {
954 + "version": "8.10.61",
955 + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.61.tgz",
956 + "integrity": "sha512-l+zSbvT8TPRaCxL1l9cwHCb0tSqGAGcjPJFItGGYat5oCTiq1uQQKYg5m7AF1mgnEBzFXGLJ2LRmNjtreRX76Q=="
957 + }
958 + }
959 + },
822 "toidentifier": { 960 "toidentifier": {
823 "version": "1.0.0", 961 "version": "1.0.0",
824 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 962 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
...@@ -855,6 +993,11 @@ ...@@ -855,6 +993,11 @@
855 "mime-types": "~2.1.24" 993 "mime-types": "~2.1.24"
856 } 994 }
857 }, 995 },
996 + "typedarray": {
997 + "version": "0.0.6",
998 + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
999 + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
1000 + },
858 "unpipe": { 1001 "unpipe": {
859 "version": "1.0.0", 1002 "version": "1.0.0",
860 "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 1003 "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
......
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
14 "cors": "^2.8.5", 14 "cors": "^2.8.5",
15 "express": "^4.17.1", 15 "express": "^4.17.1",
16 "ffmpeg": "0.0.4", 16 "ffmpeg": "0.0.4",
17 + "fs": "0.0.1-security",
18 + "node-fetch": "^2.6.0",
17 "opencv4nodejs": "^5.6.0", 19 "opencv4nodejs": "^5.6.0",
18 "path": "^0.12.7", 20 "path": "^0.12.7",
19 - "request": "^2.88.2" 21 + "request": "^2.88.2",
22 + "sync-request": "^6.1.0"
20 } 23 }
21 } 24 }
......
...@@ -12,5 +12,5 @@ app.use(bodyParser.urlencoded({limit: '100mb', extended: true})); ...@@ -12,5 +12,5 @@ app.use(bodyParser.urlencoded({limit: '100mb', extended: true}));
12 app.use(bodyParser()); 12 app.use(bodyParser());
13 app.use('/api', api); 13 app.use('/api', api);
14 14
15 -const port = 3003; 15 +const port = 3004;
16 app.listen(port, () => console.log(`노드서버 시작 : ${port}`)); 16 app.listen(port, () => console.log(`노드서버 시작 : ${port}`));
......
1 import React from 'react'; 1 import React from 'react';
2 import PropTypes from 'prop-types'; 2 import PropTypes from 'prop-types';
3 import { connect } from 'react-redux'; 3 import { connect } from 'react-redux';
4 -import { Switch, Route, withRouter, Redirect } from 'react-router'; 4 +import { Switch, Route, withRouter } from 'react-router';
5 import { TransitionGroup, CSSTransition } from 'react-transition-group'; 5 import { TransitionGroup, CSSTransition } from 'react-transition-group';
6 import Hammer from 'rc-hammerjs'; 6 import Hammer from 'rc-hammerjs';
7 7
......
...@@ -7,7 +7,6 @@ import { ...@@ -7,7 +7,6 @@ import {
7 Button, 7 Button,
8 Form, 8 Form,
9 FormGroup, 9 FormGroup,
10 - Label,
11 } from 'reactstrap'; 10 } from 'reactstrap';
12 11
13 class Subject extends PureComponent { 12 class Subject extends PureComponent {
...@@ -36,12 +35,24 @@ class Subject extends PureComponent { ...@@ -36,12 +35,24 @@ class Subject extends PureComponent {
36 35
37 onClickSaveImage(e) { 36 onClickSaveImage(e) {
38 e.preventDefault(); 37 e.preventDefault();
39 - console.log(this.state.imageFiles);
40 console.log("save image"); 38 console.log("save image");
41 - this.setState({
42 - imageFiles:[],
43 - });
44 // post request 39 // post request
40 + fetch('http://localhost:3004/api/saveImage',{
41 + method: 'POST',
42 + mode: 'cors',
43 + cache: 'no-cache',
44 + credentials: 'same-origin',
45 + headers: {
46 + 'Content-Type': 'application/json',
47 + },
48 + redirect: 'follow',
49 + referrer: 'no-referrer',
50 + body: JSON.stringify(this.state.imageFiles)
51 + })
52 + .then(res=>res.json())
53 + .then(data=>this.setState({videoAnalysisResult:data}))
54 +
55 + console.log(this.state.videoAnalysisResult);
45 } 56 }
46 57
47 render() { 58 render() {
...@@ -66,7 +77,7 @@ class Subject extends PureComponent { ...@@ -66,7 +77,7 @@ class Subject extends PureComponent {
66 /> 77 />
67 {this.state.imageFiles.length > 0 ? <div> 78 {this.state.imageFiles.length > 0 ? <div>
68 {this.state.imageFiles.map((file, idx) => ( 79 {this.state.imageFiles.map((file, idx) => (
69 - <img alt="..." src={file.preview} key={`img-id-${idx.toString()}`} />))} 80 + <img style={{height: '200px'}}alt="..." src={file.preview} key={`img-id-${idx.toString()}`} />))}
70 </div> : <img 81 </div> : <img
71 alt="..." 82 alt="..."
72 src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTEiIGhlaWdodD0iMTQxIj48cmVjdCB3aWR0aD0iMTkxIiBoZWlnaHQ9IjE0MSIgZmlsbD0iI2VlZSIvPjx0ZXh0IHRleHQtYW5jaG9yPSJtaWRkbGUiIHg9Ijk1LjUiIHk9IjcwLjUiIHN0eWxlPSJmaWxsOiNhYWE7Zm9udC13ZWlnaHQ6Ym9sZDtmb250LXNpemU6MTJweDtmb250LWZhbWlseTpBcmlhbCxIZWx2ZXRpY2Esc2Fucy1zZXJpZjtkb21pbmFudC1iYXNlbGluZTpjZW50cmFsIj4xOTF4MTQxPC90ZXh0Pjwvc3ZnPg==" 83 src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTEiIGhlaWdodD0iMTQxIj48cmVjdCB3aWR0aD0iMTkxIiBoZWlnaHQ9IjE0MSIgZmlsbD0iI2VlZSIvPjx0ZXh0IHRleHQtYW5jaG9yPSJtaWRkbGUiIHg9Ijk1LjUiIHk9IjcwLjUiIHN0eWxlPSJmaWxsOiNhYWE7Zm9udC13ZWlnaHQ6Ym9sZDtmb250LXNpemU6MTJweDtmb250LWZhbWlseTpBcmlhbCxIZWx2ZXRpY2Esc2Fucy1zZXJpZjtkb21pbmFudC1iYXNlbGluZTpjZW50cmFsIj4xOTF4MTQxPC90ZXh0Pjwvc3ZnPg=="
......
...@@ -10,6 +10,8 @@ import { ...@@ -10,6 +10,8 @@ import {
10 } from 'reactstrap'; 10 } from 'reactstrap';
11 11
12 import Widget from '../../components/Widget/Widget'; 12 import Widget from '../../components/Widget/Widget';
13 +var fireResultImages=[];
14 +var unknownResultImages=[];
13 15
14 class Dashboard extends React.Component { 16 class Dashboard extends React.Component {
15 constructor(props) { 17 constructor(props) {
...@@ -19,9 +21,13 @@ class Dashboard extends React.Component { ...@@ -19,9 +21,13 @@ class Dashboard extends React.Component {
19 // this.analysisVideo = this.analysisVideo.bind(this); 21 // this.analysisVideo = this.analysisVideo.bind(this);
20 this.state = { 22 this.state = {
21 videoFiles: [], 23 videoFiles: [],
22 - videoAnalysisResult:null 24 + videoAnalysisResult:null,
23 }; 25 };
24 } 26 }
27 +
28 + importAll(r){
29 + return r.keys().map(r);
30 + }
25 31
26 onChangeInputVideo(e) { 32 onChangeInputVideo(e) {
27 const files = []; 33 const files = [];
...@@ -39,11 +45,9 @@ class Dashboard extends React.Component { ...@@ -39,11 +45,9 @@ class Dashboard extends React.Component {
39 45
40 onClickSaveVideo(e) { 46 onClickSaveVideo(e) {
41 e.preventDefault(); 47 e.preventDefault();
42 - console.log(this.state.videoFiles);
43 console.log("upload video"); 48 console.log("upload video");
44 -
45 // post request 49 // post request
46 - fetch('http://localhost:3002/api/videoResult',{ 50 + fetch('http://localhost:3004/api/videoResult',{
47 method: 'POST', 51 method: 'POST',
48 mode: 'cors', 52 mode: 'cors',
49 cache: 'no-cache', 53 cache: 'no-cache',
...@@ -66,9 +70,13 @@ class Dashboard extends React.Component { ...@@ -66,9 +70,13 @@ class Dashboard extends React.Component {
66 performance: PropTypes.any, 70 performance: PropTypes.any,
67 }; 71 };
68 72
73 + componentWillMount(){
74 + fireResultImages= this.importAll(require.context('../../../../Back-end/fire/', false, /\.(png|jpg|svg)$/))
75 + unknownResultImages= this.importAll(require.context('../../../../Back-end/unknown/', false, /\.(png|jpg|svg)$/))
76 + }
77 +
69 render() { 78 render() {
70 - console.log("render") 79 + console.log(this.state.videoAnalysisResult);
71 - console.log(this.state.videoFiles)
72 return ( 80 return (
73 <div> 81 <div>
74 <h1 className="page-title">Video Analysis <small><small>Performance</small></small></h1> 82 <h1 className="page-title">Video Analysis <small><small>Performance</small></small></h1>
...@@ -100,9 +108,20 @@ class Dashboard extends React.Component { ...@@ -100,9 +108,20 @@ class Dashboard extends React.Component {
100 title={<h5><span className="fw-semi-bold">Results</span></h5>} 108 title={<h5><span className="fw-semi-bold">Results</span></h5>}
101 > 109 >
102 <div> 110 <div>
103 - <div className="text-center" style={{ height: '300px' }} /> 111 + {fireResultImages.length > 0 ? <div>
104 - <p className="fs-mini text-muted"> 112 + <p className="fw-semi-bold"> 불났어요!!
105 </p> 113 </p>
114 + {fireResultImages.map(
115 + (image, index) => <img style={{height: '200px', margin: '10px 10px 10px 10px'}}alt="..." key={index} src={image}/>)}
116 + </div> : <div/>}
117 + </div>
118 + <div>
119 + {unknownResultImages.length > 0 ? <div>
120 + <p className="fw-semi-bold"> 침입자 발생!!
121 + </p>
122 + {unknownResultImages.map(
123 + (image, index) => <img style={{height: '200px', margin: '10px 10px 10px 10px'}}alt="..." key={index} src={image}/>)}
124 + </div> : <div/>}
106 </div> 125 </div>
107 </Widget> 126 </Widget>
108 </Col> 127 </Col>
...@@ -118,23 +137,4 @@ function mapStateToProps(state) { ...@@ -118,23 +137,4 @@ function mapStateToProps(state) {
118 } 137 }
119 } 138 }
120 139
121 -
122 -export default connect(mapStateToProps)(Dashboard);
123 -
124 -function postData(url = '', data = {}) {
125 - // Default options are marked with *
126 - return fetch(url, {
127 - method: 'POST', // *GET, POST, PUT, DELETE, etc.
128 - mode: 'cors', // no-cors, cors, *same-origin
129 - cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
130 - credentials: 'same-origin', // include, *same-origin, omit
131 - headers: {
132 - 'Content-Type': 'application/json',
133 - // 'Content-Type': 'application/x-www-form-urlencoded',
134 - },
135 - redirect: 'follow', // manual, *follow, error
136 - referrer: 'no-referrer', // no-referrer, *client
137 - body: JSON.stringify(data), // body data type must match "Content-Type" header
138 - })
139 - .then(response => response.json()); // parses JSON response into native JavaScript objects
140 -}
...\ No newline at end of file ...\ No newline at end of file
140 +export default connect(mapStateToProps)(Dashboard);
...\ No newline at end of file ...\ No newline at end of file
......