-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdat2csv.py
More file actions
46 lines (26 loc) · 816 Bytes
/
dat2csv.py
File metadata and controls
46 lines (26 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import argparse
import os
import glob
import csv
def argument():
parser = argparse.ArgumentParser()
parser.add_argument('--source', default='../nlpr/data/annotation', type=str)
parser.add_argument('--dataset', default='1', type=str)
args = parser.parse_args()
return args
def main(args):
dats = glob.glob(os.path.join(args.source, f'Dataset{args.dataset}', '*.dat'))
for dat in dats:
output_file = open(dat.replace('.dat', '.csv'), 'w', newline='')
writer = csv.writer(output_file)
writer.writerow(["cid", "fid", "pid", "x1", "y1", "w", "h"])
with open(dat) as f:
lines = f.read().split('\n')
for line in lines:
if line == '':
continue
row = [ int(c) for c in line.split(' ') ]
writer.writerow(row)
if __name__ == '__main__':
args = argument()
main(args)