-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_kinematic_contraints.py
107 lines (88 loc) · 3.59 KB
/
plot_kinematic_contraints.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
""" Play around with kinematic constraints. """
from collections import defaultdict
import argparse
import numpy as np
import cv2
from tqdm import tqdm
from config.Model import Model
from pose_network.core.Types import *
from datareader.reader_labeled import build_dataflow, df2dict
from utils.plot_util import draw_skel
from utils.mpl_setup import plt_figure
from utils.StitchedImage import StitchedImage
import utils.CamLib as cl
def _get_coord(xyz, id_list):
id_list = np.array(id_list).reshape([-1, 1])
return np.mean(xyz[id_list], 0).squeeze()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Show labeled datasets.')
parser.add_argument('model', type=str, help='Model definition file.')
parser.add_argument('--set_name', type=str, default='train')
parser.add_argument('--wait', action='store_true', help='Wait after each frame shown.')
parser.add_argument('--window_size', type=int, default=1200, help='Window used for visualization.')
parser.add_argument('--debug', action='store_true', help='Debug mode: Only subset of data is used.')
args = parser.parse_args()
model = Model(args.model)
df = build_dataflow(model, [args.set_name], is_train=False,
threaded=False, single_sample=False)
# data container to store all the body parameters we look at
values = defaultdict(list)
start = None
for idx, dp in tqdm(enumerate(df.get_data()), desc='Accumulating stats', total=df.size()):
if idx >= 100 and args.debug:
break
if idx >= df.size():
break
data = df2dict(dp)
xyz = data[data_t.xyz_nobatch][0]
vis = data[data_t.vis_nobatch]
if np.sum(vis) < 12:
# print('Not all vis', np.sum(vis))
continue
# limb lengths
limbs = dict()
for lid, (inds, _) in enumerate(model.limbs):
pid, cid = inds
values['limb%d' % lid].append(
np.linalg.norm(_get_coord(xyz, cid) - _get_coord(xyz, pid), 2, -1)
)
# angles between dependent limbs
for k, (lid1, lid2) in enumerate(model.data['kinematic_dep']):
cid, pid = model.limbs[lid1][0]
limb1 = _get_coord(xyz, cid) - _get_coord(xyz, pid)
cid, pid = model.limbs[lid2][0]
limb2 = _get_coord(xyz, cid) - _get_coord(xyz, pid)
limb1 /= np.linalg.norm(limb1, 2)
limb2 /= np.linalg.norm(limb2, 2)
values['pair%d' % k].append(
np.dot(limb1, limb2)
)
import matplotlib.pyplot as plt
# # visualize distributions: Bone lengths
# for lid, (inds, _) in enumerate(model.limbs):
# pid, cid = inds
# if type(pid) == int:
# pid = [pid]
# if type(cid) == int:
# cid = [cid]
#
# n1 = [model.keypoints[x][0] for x in pid]
# n2 = [model.keypoints[x][0] for x in cid]
# print(n1, 'to', n2)
#
# print('min, max: [%.3f, %.3f]' % (np.quantile(values['limb%d' % lid], 0.05),
# np.quantile(values['limb%d' % lid], 0.95)))
#
# # fig, ax = plt.subplots(1, 1)
# # ax.hist(values['limb%d' % lid])
# # plt.show()
# visualize distributions: Bone angles
for k, v in values.items():
if 'pair' not in k:
continue
print(k)
print('min, max: [%.3f, %.3f]' % (np.quantile(v, 0.05),
np.quantile(v, 0.95)))
fig, ax = plt.subplots(1, 1)
ax.hist(np.arccos(v)*180./np.pi)
plt.show()