박선진

코드 정리 + 테스트 데이터 추가

...@@ -8,6 +8,7 @@ const router = express.Router(); ...@@ -8,6 +8,7 @@ const router = express.Router();
8 router.post('/videoResult', function (req, res) { 8 router.post('/videoResult', function (req, res) {
9 delete_prevResult_image('./fire'); 9 delete_prevResult_image('./fire');
10 delete_prevResult_image('./unknown'); 10 delete_prevResult_image('./unknown');
11 + delete_prevResult_image('./data');
11 try { 12 try {
12 let preview = req.body[0].preview; 13 let preview = req.body[0].preview;
13 14
...@@ -29,7 +30,7 @@ router.post('/videoResult', function (req, res) { ...@@ -29,7 +30,7 @@ router.post('/videoResult', function (req, res) {
29 file_name: 'frame_%s' 30 file_name: 'frame_%s'
30 }, function (error, files) { 31 }, function (error, files) {
31 if (!error) 32 if (!error)
32 - for(var i=0;i<files.length-1;i++){ 33 + for (var i = 0; i < files.length - 1; i++) {
33 let base64str = base64_encode(files[i]); 34 let base64str = base64_encode(files[i]);
34 request.post({ 35 request.post({
35 url: 'http://101.101.210.73/process', 36 url: 'http://101.101.210.73/process',
...@@ -40,11 +41,11 @@ router.post('/videoResult', function (req, res) { ...@@ -40,11 +41,11 @@ router.post('/videoResult', function (req, res) {
40 json: true 41 json: true
41 }, (err, response, body) => { 42 }, (err, response, body) => {
42 console.log(body) 43 console.log(body)
43 - var index=body['index']; 44 + var index = body['index'];
44 - if(body['unknown_person'] == true){ 45 + if (body['unknown_person'] == true) {
45 save_Result_image((files[index]), 'unknown', index); 46 save_Result_image((files[index]), 'unknown', index);
46 } 47 }
47 - if(body['fire_broken'] == true){ 48 + if (body['fire_broken'] == true) {
48 save_Result_image((files[index]), 'fire', index); 49 save_Result_image((files[index]), 'fire', index);
49 } 50 }
50 }) 51 })
...@@ -88,24 +89,19 @@ function base64_encode(file) { ...@@ -88,24 +89,19 @@ function base64_encode(file) {
88 return new Buffer(bitmap).toString('base64'); 89 return new Buffer(bitmap).toString('base64');
89 } 90 }
90 91
91 -function save_Result_image(file, type, index){ 92 +function save_Result_image(file, type, index) {
92 var bitmap = fs.readFileSync(file); 93 var bitmap = fs.readFileSync(file);
93 var filePath = './' + type + '/' + index + '.jpg'; 94 var filePath = './' + type + '/' + index + '.jpg';
94 - fs.writeFile(filePath, bitmap, function(err){ 95 + fs.writeFile(filePath, bitmap, function (err) {
95 console.log('save'); 96 console.log('save');
96 }); 97 });
97 } 98 }
98 99
99 -function delete_prevResult_image(filePath){ 100 +function delete_prevResult_image(filePath) {
100 - fs.readdir(filePath, (err, files) => { 101 + let files = fs.readdirSync(filePath);
101 - if (err) throw err;
102 -
103 for (const file of files) { 102 for (const file of files) {
104 - fs.unlink(path.join(filePath, file), err => { 103 + fs.unlinkSync(path.join(filePath, file));
105 - if (err) throw err;
106 - });
107 } 104 }
108 - });
109 } 105 }
110 106
111 module.exports = router; 107 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
This file is too large to display.