summaryrefslogtreecommitdiffstats
path: root/data/combined/limbs-avg.py
diff options
context:
space:
mode:
authorJon Whiteaker <jbw@berkeley.edu>2012-02-22 16:10:15 -0800
committerJon Whiteaker <jbw@berkeley.edu>2012-02-22 16:10:15 -0800
commitd9c41d3c4ad0e006e719892a00bdb40874830ae2 (patch)
treec952f5fb76e8a874e62fad1994e7e53489c9db79 /data/combined/limbs-avg.py
parentfb534c575541ba6ad8a9f84872bab14e44e44264 (diff)
downloadkinect-d9c41d3c4ad0e006e719892a00bdb40874830ae2.tar.gz
new combined data
Diffstat (limited to 'data/combined/limbs-avg.py')
-rwxr-xr-xdata/combined/limbs-avg.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/data/combined/limbs-avg.py b/data/combined/limbs-avg.py
new file mode 100755
index 0000000..031f80b
--- /dev/null
+++ b/data/combined/limbs-avg.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+import sys
+import math
+import pickle
+import numpy as np
+
+sk_file = open(sys.argv[1])
+out_dir = sys.argv[1][0:sys.argv[1].rfind('/')+1]
+dirs = ['24-1-2012-16-56-57','27-1-2012-10-45-29']
+names = pickle.load(open(sys.argv[2]))
+labels = []
+for f in sys.argv[3:]:
+ labels += [pickle.load(open(f))]
+flabel = labels[0]
+for label in labels:
+ for run in label:
+ if label[run] != flabel[run] or label[run] == '?' or label[run] == 'None':
+ flabel[run] = 'None'
+
+pframe = 0
+vals = {}
+data = {}
+limbs = (('Head','ShoulderCenter'),\
+ ('ShoulderCenter','ShoulderLeft'),('ShoulderLeft','ElbowLeft'),('ElbowLeft','WristLeft'),\
+ ('ShoulderCenter','ShoulderRight'),('ShoulderRight','ElbowRight'),('ElbowRight','WristRight'),\
+ ('ShoulderCenter','Spine'),('Spine','HipCenter'),\
+ ('HipCenter','HipLeft'),('HipLeft','KneeLeft'),('KneeLeft','AnkleLeft'),\
+ ('HipCenter','HipRight'),('HipRight','KneeRight'),('KneeRight','AnkleRight'))
+dupes = ((1,4),(2,5),(3,6),(9,12),(10,13),(11,14))
+#xlabels = ('h-sc','sc-sl','sl-el','el-wl','sc-sr','sr-er','er-wr','sc-s','s-hc','hc-hl','hl-kl','kl-al','hc-hr','hr-kr','kr-ar')
+xlabels = ('h-sc','sc-sh','sh-el','el-wr','sc-s','s-hc','hc-hi','hi-kn','kn-an')
+print '# '+','.join(['dir','name','run','frame','z-value','z-var']+list(xlabels))
+
+
+for line in sk_file:
+ dir, run, frame, nid, joint, state, x, y, z, X, Y = line.strip().split(',')
+ if frame != 'Frame':
+ run = int(run)
+ frame = int(frame)
+ if frame != pframe and vals != {} and run in flabel and flabel[run] != 'None':
+ out = []
+ zv = map(lambda xyz: xyz[2], vals.values())
+ for l in range(len(limbs)):
+ j1, j2 = limbs[l]
+ if j1 in vals and j2 in vals:
+ dx = vals[j1][0] - vals[j2][0]
+ dy = vals[j1][1] - vals[j2][1]
+ dz = vals[j1][2] - vals[j2][2]
+ limb = math.sqrt(dx*dx + dy*dy + dz*dz)
+ out += [str(limb)]
+ #zv += [(vals[j1][2] + vals[j2][2])/2]
+ #dist = math.fabs((dz + 2*vals[j2][2])/2)
+ #if limb < 1000 and limb > 100:
+ #X += [dist]
+ #data[name][l] += [limb]
+ #print str(dist) + " " + str(limb)
+ #print str(dist) + "\t" + str(limb)
+ else:
+ out += ['-1']
+ for l in range(len(dupes)-1,-1,-1):
+ l1, l2 = dupes[l]
+ if out[l1] != '-1' and out[l2] != '-1':
+ out[l1] = str((float(out[l1])+float(out[l2]))/2)
+ elif out[l1] == '-1' and out[l2] != '-1':
+ out[l1] = out[l2]
+ out.pop(l2)
+ if len(zv) >= 1:
+ print ','.join(str(dirs.index(dir) + 1),str(names.index([flabel[run]) + 1),str(run),str(frame),str(np.average(zv)),str(np.var(zv))] + out)
+ vals = {}
+ if state == 'Tracked':
+ vals[joint] = [float(x), float(y), float(z)]
+ pframe = frame
+