-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisam2g2o.py
executable file
·61 lines (49 loc) · 1.96 KB
/
isam2g2o.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
#
# This script will plot the distribution of the noise in the cityTrees10000 dataset and try to extract its paremeters.
# License: GPLv3
# author: Felipe Inostroza 2016
import sys
import os.path
import numpy as np
import argparse
import progressbar
parser = argparse.ArgumentParser(description='Convert a folder from isam style datasets to g2o style.')
parser.add_argument('datasetFolder', metavar='folder',
help='The folder to read datasets')
parser.add_argument('resultsFolder', metavar='results',
help='The folder to store converted datasets')
parser.add_argument('-n','--numposes',type=int, default=-1,
help='The maximum number of trayectory poses to read (truncate dataset)')
args = parser.parse_args()
if not os.path.isdir(args.datasetFolder):
print(args.datasetFolder+ ' is not a folder!')
sys.exit(0);
if not os.path.isdir(args.resultsFolder):
print(args.resultsFolder+ ' is not a folder!')
sys.exit(0);
files = os.listdir(args.datasetFolder)
bar = progressbar.ProgressBar()
for f in bar(files):
infile = os.path.join(args.datasetFolder,f)
filename, extention = os.path.splitext(os.path.basename(infile))
outfile = os.path.join(args.resultsFolder, filename +'.g2o');
isamFile = open(infile, "r")
g2oFile = open(outfile , "w")
for line in isamFile:
if line.startswith('EDGE2'):
g2oline = 'EDGE_SE2' + line[5:]
if line.startswith('LANDMARK'):
data = np.fromstring(line[8:] , sep=' ');
if int(args.numposes) >0 and int(data[0]) > int(args.numposes):
break
data[1] = data[1] +100000
g2oline = 'EDGE_SE2_XY'
g2oline = g2oline + ' ' + str( int(data[0]) ) + ' ' + str(int(data[1]))
for s in data[2:]:
g2oline = g2oline + ' ' +str(s)
g2oline = g2oline + '\n'
g2oFile.write(g2oline)
g2oFile.write('FIX 0\n')
isamFile.close()
g2oFile.close()