-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
20 lines (19 loc) · 855 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var fs = require('fs-extra'),
xml2js = require('xml2js'),
_=require('lodash');
const filenames = fs.readdirSync(__dirname+'/labels');
var parser = new xml2js.Parser();
filenames.forEach(eachfile=>{
filedata = fs.readFileSync(__dirname+'/labels/'+eachfile);
parser.parseString(filedata,(err,result)=>{
console.log(result);
boxes = _.get(result,'annotation.object');
res = _.map(boxes,eachbox=>{
console.log(eachbox);
let { xmin,ymin,xmax,ymax} = eachbox.bndbox[0];
return `${xmin},${ymin},${xmin},${ymax},${xmax},${ymax},${xmax},${ymin}`
})
fs.writeFileSync(__dirname + '/newlabels/gt_' + eachfile.split('.xml')[0] + '.txt',res.join('\n'))
parser.reset();
});
})