summaryrefslogtreecommitdiffstats
path: root/data/limbs.py
blob: 61794ec9ded39a4bf748c482ce061a998e8234bc (plain)
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
62
#!/usr/bin/python

import sys
import math
import pickle

sk_file = open(sys.argv[1])
out_dir = sys.argv[1][0:sys.argv[1].rfind('/')+1]
labels = []
for f in sys.argv[2:]:
    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'))
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')
print '# '+','.join(['name','run','frame','z-value']+list(xlabels))


for line in sk_file:
    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 = []
            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 += ['?']
            if len(zv) >= 1:
                print ','.join([flabel[run],str(run),str(frame),str(sum(zv)/len(zv))] + out)
            vals = {}
        if state == 'Tracked':
            vals[joint] = [float(x), float(y), float(z)]
        pframe = frame