Skip to content

Commit a2ce0c0

Browse files
author
James Clarkson
committedJun 21, 2016
Initial commit
0 parents  commit a2ce0c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5228
-0
lines changed
 

‎.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target/
2+
conf/kfusion.env
3+
.classpath
4+
.project
5+
.settings

‎bin/checkPos.py

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/usr/bin/python
2+
# Copyright (c) 2014 University of Edinburgh, Imperial College, University of Manchester.
3+
# Developed in the PAMELA project, EPSRC Programme Grant EP/K008730/1
4+
#
5+
# This code is licensed under the MIT License.
6+
7+
import sys
8+
import re
9+
import math
10+
import numpy
11+
12+
13+
kfusion_log_regex = "([0-9]+[\s]*)\\t"
14+
kfusion_log_regex += 8 * "([0-9.]+)\\t"
15+
kfusion_log_regex += 3 * "([-0-9.]+)\\t"
16+
kfusion_log_regex += "([01])\s+([01])"
17+
18+
nuim_log_regex = "([0-9]+)"
19+
nuim_log_regex += 7 * "\\s+([-0-9e.]+)\\s*"
20+
21+
22+
# open files
23+
24+
if len(sys.argv) != 3 :
25+
print "I need two parameters, the benchmark log file and the original scene camera position file."
26+
exit (1)
27+
28+
# open benchmark log file first
29+
print "Get KFusion output data."
30+
framesDropped = 0
31+
validFrames = 0
32+
lastFrame = -1
33+
untracked = -4;
34+
kfusion_traj = []
35+
fileref = open(sys.argv[1],'r')
36+
data = fileref.read()
37+
fileref.close()
38+
lines = data.split("\n") # remove head + first line
39+
headers = lines[0].split("\t")
40+
fulldata = {}
41+
if len(headers) == 15 :
42+
if headers[14] == "" :
43+
del headers[14]
44+
if len(headers) != 14 :
45+
print "Wrong KFusion log file. Expected 14 columns but found " + str(len(headers))
46+
exit(1)
47+
for variable in headers :
48+
fulldata[variable] = []
49+
50+
for line in lines[1:] :
51+
matching = re.match(kfusion_log_regex,line)
52+
if matching :
53+
dropped = int( matching.group(1)) - lastFrame - 1
54+
if dropped>0:
55+
framesDropped = framesDropped + dropped
56+
for pad in range(0,dropped) :
57+
kfusion_traj.append( lastValid )
58+
59+
kfusion_traj.append( (matching.group(10),matching.group(11),matching.group(12),matching.group(13),1 ) )
60+
lastValid = (matching.group(10),matching.group(11),matching.group(12),matching.group(13), 0)
61+
if int(matching.group(13)) == 0 :
62+
untracked = untracked+1
63+
validFrames = validFrames +1
64+
for elem_idx in range(len(headers)) :
65+
fulldata[headers[elem_idx]].append(float(matching.group(elem_idx+1)))
66+
67+
lastFrame = int(matching.group(1))
68+
else :
69+
#print "Skip KFusion line : " + line
70+
break
71+
72+
# open benchmark log file first
73+
nuim_traj = []
74+
fileref = open(sys.argv[2],'r')
75+
data = fileref.read()
76+
fileref.close()
77+
lines = data.split("\n") # remove head + first line
78+
for line in lines :
79+
matching = re.match(nuim_log_regex,line)
80+
if matching :
81+
nuim_traj.append( (matching.group(2),matching.group(3),matching.group(4)) )
82+
else :
83+
#print "Skip nuim line : " + line
84+
break
85+
86+
working_position = min ( len(kfusion_traj) , len(nuim_traj) )
87+
print "KFusion valid frames " + str(validFrames) + ", dropped frames: " + str(framesDropped)
88+
print "KFusion result : " + str(len(kfusion_traj)) + " positions."
89+
print "NUIM result : " + str(len(nuim_traj)) + " positions."
90+
print "Working position is : " + str(working_position)
91+
print "Untracked frames: " +str(untracked)
92+
nuim_traj=nuim_traj[0:working_position]
93+
kfusion_traj=kfusion_traj[0:working_position]
94+
95+
print "Shift KFusion trajectory..."
96+
97+
first = nuim_traj[0]
98+
fulldata["ATE"] = []
99+
#ATE_wrt_kfusion does not consider the ATE for frames which were dropped if we are running in non process-every-frame mode
100+
fulldata["ATE_wrt_kfusion"] = []
101+
distance_since_valid=0;
102+
#print "Frame speed(m/s) dlv(m) ATE(m) valid tracked"
103+
for p in range(working_position) :
104+
kfusion_traj[p] = (float(kfusion_traj[p][0]) + float(first[0]) , - (float(kfusion_traj[p][1]) + float(first[1]) ) , float(kfusion_traj[p][2]) + float(first[2]), int(kfusion_traj[p][3]),int(kfusion_traj[p][4]) )
105+
diff = (abs( kfusion_traj[p][0] - float(nuim_traj[p][0])) , abs( kfusion_traj[p][1] - float(nuim_traj[p][1] )) , abs( kfusion_traj[p][2] - float(nuim_traj[p][2] )) )
106+
ate=math.sqrt(sum(( diff[0] * diff[0], diff[1] * diff[1], diff[2] * diff[2])))
107+
108+
if( p==1 ):
109+
lastValid = nuim_traj[p]
110+
if 1 ==1 :
111+
dx = float(nuim_traj[p][0]) - float(lastValid[0])
112+
dy = float(nuim_traj[p][1]) - float(lastValid[1])
113+
dz = float(nuim_traj[p][2]) - float(lastValid[2])
114+
distA = math.sqrt((dx*dx) + (dz*dz))
115+
dist = math.sqrt( (dy*dy) + (distA *distA))
116+
speed = dist/0.0333
117+
if (kfusion_traj[p][3]==0):
118+
tracked = "untracked"
119+
else:
120+
tracked = ""
121+
if (kfusion_traj[p][4]==0):
122+
valid = "dropped"
123+
else:
124+
valid = "-"
125+
distance_since_valid = distance_since_valid + dist
126+
# print "%4d %6.6f %6.6f %6.6f %10s %10s"% (p, speed, distance_since_valid, ate, valid, tracked )
127+
lastValid = nuim_traj[p]
128+
if kfusion_traj[p][4]==1:
129+
distance_since_valid= 0
130+
131+
if (kfusion_traj[p][4] == 1 ):
132+
fulldata["ATE_wrt_kfusion"].append(ate)
133+
fulldata["ATE"].append(ate)
134+
135+
#print "The following are designed to enable easy macchine readability of key data"
136+
#print "MRkey:,logfile,ATE,computaion,dropped,untracked"
137+
#print ("MRdata:,%s,%6.6f,%6.6f,%d,%d") % ( sys.argv[1], numpy.mean(fulldata["ATE"]), numpy.mean(fulldata["computation"]), framesDropped, untracked)
138+
139+
print "\nA detailed statistical analysis is provided."
140+
print "Runtimes are in seconds and the absolute trajectory error (ATE) is in meters."
141+
print "The ATE measure accuracy, check this number to see how precise your computation is."
142+
print "Acceptable values are in the range of few centimeters."
143+
144+
for variable in sorted(fulldata.keys()) :
145+
if "X" in variable or "Z" in variable or "Y" in variable or "frame" in variable or "tracked" in variable or "integrated" in variable :
146+
continue
147+
148+
if (framesDropped == 0) and (str(variable) == "ATE_wrt_kfusion"):
149+
continue
150+
151+
print "%20.20s" % str(variable),
152+
print "\tMin : %6.6f" % min(fulldata[variable]),
153+
print "\tMax : %0.6f" % max(fulldata[variable]),
154+
print "\tMean : %0.6f" % numpy.mean(fulldata[variable]),
155+
print "\tTotal : %0.8f" % sum(fulldata[variable])
156+
157+
#first2 = []S
158+
#derive = []
159+
160+
#for row_idx in range(len(rows1)) :
161+
# col1 = rows1[row_idx].split("\t")
162+
# col2 = rows2[row_idx].split(" ")
163+
# v1 = col1[8:11]
164+
# v2 = col2[1:4]
165+
# if first2 == [] :
166+
# first2 = v2
167+
# v1 = [float(v1[0]) + float(first2[0]) , - (float(v1[1]) + float(first2[1]) ) , float(v1[2]) + float(first2[2]) ]
168+
# derive.append([abs(float(v1[0]) - float(v2[0])) , abs (float(v1[1]) - float(v2[1]) ) , abs(float(v1[2]) - float(v2[2])) ])
169+
170+
#maxderive = reduce(lambda a,d: [max(a[0] , d[0]),max(a[1] , d[1]),max(a[2] , d[2])], derive, [0.0,0.0,0.0])
171+
#minderive = reduce(lambda a,d: [min(a[0] , d[0]),min(a[1] , d[1]),min(a[2] , d[2])], derive, [1000000,10000000.0,10000000.0])
172+
#total = map(lambda x: x/len(rows1), reduce(lambda a,d: [a[0] + d[0],a[1] + d[1],a[2] + d[2]], derive, [0.0,0.0,0.0]))
173+
174+
#print "Min derivation : " + str(min(minderive))
175+
#print "Max derivation : " + str(max(maxderive))
176+
#print "Average derivation : " + str(total[0])

0 commit comments

Comments
 (0)
Please sign in to comment.