박선진

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

......@@ -8,6 +8,7 @@ const router = express.Router();
router.post('/videoResult', function (req, res) {
delete_prevResult_image('./fire');
delete_prevResult_image('./unknown');
delete_prevResult_image('./data');
try {
let preview = req.body[0].preview;
......@@ -29,26 +30,26 @@ router.post('/videoResult', function (req, res) {
file_name: 'frame_%s'
}, function (error, files) {
if (!error)
for(var i=0;i<files.length-1;i++){
let base64str = base64_encode(files[i]);
request.post({
url: 'http://101.101.210.73/process',
form: {
'data': base64str,
'index': i
},
json: true
}, (err, response, body) => {
console.log(body)
var index=body['index'];
if(body['unknown_person'] == true){
save_Result_image((files[index]), 'unknown', index);
}
if(body['fire_broken'] == true){
save_Result_image((files[index]), 'fire', index);
}
})
}
for (var i = 0; i < files.length - 1; i++) {
let base64str = base64_encode(files[i]);
request.post({
url: 'http://101.101.210.73/process',
form: {
'data': base64str,
'index': i
},
json: true
}, (err, response, body) => {
console.log(body)
var index = body['index'];
if (body['unknown_person'] == true) {
save_Result_image((files[index]), 'unknown', index);
}
if (body['fire_broken'] == true) {
save_Result_image((files[index]), 'fire', index);
}
})
}
}
)
})
......@@ -88,24 +89,19 @@ function base64_encode(file) {
return new Buffer(bitmap).toString('base64');
}
function save_Result_image(file, type, index){
function save_Result_image(file, type, index) {
var bitmap = fs.readFileSync(file);
var filePath = './' + type + '/' + index + '.jpg';
fs.writeFile(filePath, bitmap, function(err){
fs.writeFile(filePath, bitmap, function (err) {
console.log('save');
});
}
function delete_prevResult_image(filePath){
fs.readdir(filePath, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(filePath, file), err => {
if (err) throw err;
});
}
});
function delete_prevResult_image(filePath) {
let files = fs.readdirSync(filePath);
for (const file of files) {
fs.unlinkSync(path.join(filePath, file));
}
}
module.exports = router;
\ No newline at end of file
......
This file is too large to display.