-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_pose.py
executable file
·306 lines (214 loc) · 13.1 KB
/
generate_pose.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import numpy as np
import random
from opendr.renderer import ColoredRenderer
from opendr.lighting import LambertianPointLight
from opendr.camera import ProjectPoints
from smpl.smpl_webuser.serialization import load_model
#volumetric pose gen libraries
import lib_visualization as libVisualization
import lib_kinematics as libKinematics
import lib_render as libRender
from process_yash_data import ProcessYashData
#import dart_skel_sim
#ROS
try:
import rospy
import tf
except:
pass
import tensorflow as tensorflow
import cPickle as pickle
#IKPY
from ikpy.chain import Chain
from ikpy.link import OriginLink, URDFLink
#MISC
import time as time
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#hmr
from hmr.src.tf_smpl.batch_smpl import SMPL
class GeneratePose():
def __init__(self, sampling = "NORMAL", sigma = 0, one_side_range = 0, gender="m"):
## Load SMPL model (here we load the female model)
model_path = '/home/henry/git/SMPL_python_v.1.0.0/smpl/models/basicModel_'+gender+'_lbs_10_207_0_v1.0.0.pkl'
self.m = load_model(model_path)
## Assign random pose and shape parameters
self.m.betas[:] = np.random.rand(self.m.betas.size) * .0
#self.m.betas[5] = 20.
self.m.pose[0] = 0 #pitch rotation of the person in space. 0 means the person is upside down facing back. pi is standing up facing forward
self.m.pose[1] = 0 #roll of the person in space. -pi/2 means they are tilted to their right side
self.m.pose[2] = 0#-np.pi/4 #yaw of the person in space, like turning around normal to the ground
self.m.pose[3] = 0#-np.pi/4 #left hip extension (i.e. leg bends back for np.pi/2)
self.m.pose[4] = 0#np.pi/8 #left leg yaw about hip, where np.pi/2 makes bowed leg
self.m.pose[5] = 0.#np.pi/4 #left leg abduction (POS) /adduction (NEG)
self.m.pose[6] = 0#-np.pi/4 #right hip extension (i.e. leg bends back for np.pi/2)
self.m.pose[7] = 0#-np.pi/8
self.m.pose[8] = 0.#-np.pi/4 #right leg abduction (NEG) /adduction (POS)
self.m.pose[9] = 0 #bending of spine at hips. np.pi/2 means person bends down to touch the ground
self.m.pose[10] = 0 #twisting of spine at hips. body above spine yaws normal to the ground
self.m.pose[11] = 0 #bending of spine at hips. np.pi/2 means person bends down sideways to touch the ground 3
self.m.pose[12] = 0#np.pi/4 #left knee extension. (i.e. knee bends back for np.pi/2)
self.m.pose[13] = 0 #twisting of knee normal to ground. KEEP AT ZERO
self.m.pose[14] = 0 #bending of knee sideways. KEEP AT ZERO
self.m.pose[15] = 0#np.pi/4 #right knee extension (i.e. knee bends back for np.pi/2)
self.m.pose[18] = 0 #bending at mid spine. makes person into a hunchback for positive values
self.m.pose[19] = 0#twisting of midspine. body above midspine yaws normal to the ground
self.m.pose[20] = 0 #bending of midspine, np.pi/2 means person bends down sideways to touch ground 6
self.m.pose[21] = 0 #left ankle flexion/extension
self.m.pose[22] = 0 #left ankle yaw about leg
self.m.pose[23] = 0 #left ankle twist KEEP CLOSE TO ZERO
self.m.pose[24] = 0 #right ankle flexion/extension
self.m.pose[25] = 0 #right ankle yaw about leg
self.m.pose[26] = 0#np.pi/4 #right ankle twist KEEP CLOSE TO ZERO
self.m.pose[27] = 0 #bending at upperspine. makes person into a hunchback for positive values
self.m.pose[28] = 0#twisting of upperspine. body above upperspine yaws normal to the ground
self.m.pose[29] = 0 #bending of upperspine, np.pi/2 means person bends down sideways to touch ground 9
self.m.pose[30] = 0 #flexion/extension of left ankle midpoint
self.m.pose[33] = 0 #flexion/extension of right ankle midpoint
self.m.pose[36] = 0#np.pi/2 #flexion/extension of neck. i.e. whiplash 12
self.m.pose[37] = 0#-np.pi/2 #yaw of neck
self.m.pose[38] = 0#np.pi/4 #tilt head side to side
self.m.pose[39] = 0 #left inner shoulder roll
self.m.pose[40] = 0 #left inner shoulder yaw, negative moves forward
self.m.pose[41] = 0.#np.pi/4 #left inner shoulder pitch, positive moves up
self.m.pose[42] = 0
self.m.pose[43] = 0 #right inner shoulder yaw, positive moves forward
self.m.pose[44] = 0.#-np.pi/4 #right inner shoulder pitch, positive moves down
self.m.pose[45] = 0 #flexion/extension of head 15
self.m.pose[48] = 0#-np.pi/4 #left outer shoulder roll
self.m.pose[49] = 0#-np.pi/4
self.m.pose[50] = 0#np.pi/4 #left outer shoulder pitch
self.m.pose[51] = 0#-np.pi/4 #right outer shoulder roll
self.m.pose[52] = 0#np.pi/4
self.m.pose[53] = 0#-np.pi/4
self.m.pose[54] = 0 #left elbow roll KEEP AT ZERO
self.m.pose[55] = 0#np.pi/3 #left elbow flexion/extension. KEEP NEGATIVE
self.m.pose[56] = 0 #left elbow KEEP AT ZERO
self.m.pose[57] = 0
self.m.pose[58] = 0#np.pi/4 #right elbow flexsion/extension KEEP POSITIVE
self.m.pose[60] = 0 #left wrist roll
self.m.pose[63] = 0 #right wrist roll
#self.m.pose[65] = np.pi/5
self.m.pose[66] = 0 #left hand roll
self.m.pose[69] = 0 #right hand roll
#self.m.pose[71] = np.pi/5 #right fist
mu = 0
for i in range(10):
if sampling == "NORMAL":
self.m.betas[i] = random.normalvariate(mu, sigma)
elif sampling == "UNIFORM":
self.m.betas[i] = np.random.uniform(-one_side_range, one_side_range)
#self.m.betas[0] = random.normalvariate(mu, sigma) #overall body size. more positive number makes smaller, negative makes larger with bigger belly
#self.m.betas[1] = random.normalvariate(mu, sigma) #positive number makes person very skinny, negative makes fat
#self.m.betas[2] = random.normalvariate(mu, sigma) #muscle mass. higher makes person less physically fit
#self.m.betas[3] = random.normalvariate(mu, sigma) #proportion for upper vs lower bone lengths. more negative number makes legs much bigger than arms
#self.m.betas[4] = random.normalvariate(mu, sigma) #neck. more negative seems to make neck longer and body more skinny
#self.m.betas[5] = random.normalvariate(mu, sigma) #size of hips. larger means bigger hips
#self.m.betas[6] = random.normalvariate(mu, sigma) #proportion of belly with respect to rest of the body. higher number is larger belly
#self.m.betas[7] = random.normalvariate(mu, sigma)
#self.m.betas[8] = random.normalvariate(-3, 3)
#self.m.betas[9] = random.normalvariate(-3, 3)
#print self.m.pose.shape
#print self.m.pose, 'pose'
#print self.m.betas, 'betas'
def map_yash_to_smpl_angles(self, verbose = True):
movements = ['LL', 'RL', 'LH1', 'LH2', 'LH3', 'RH1', 'RH2', 'RH3']
subjects = ['FMNGQ']#['40ESJ', '4ZZZQ', '5LDJG', 'A4G4Y','G55Q1','GF5Q3', 'GRTJK', 'RQCLC', 'TSQNA', 'TX887', 'WCNOM', 'WE2SZ', 'WFGW9', 'WM9KJ', 'ZV7TE']
for subject in subjects:
for movement in movements:
print "subject: ", subject, " movement: ", movement
filename = "/media/henry/multimodal_data_2/pressure_mat_pose_data/subject_" + subject + "/" + movement + "_angles.p"
with open(filename, 'rb') as fp:
angles_data = pickle.load(fp)
for entry in angles_data:
#entry = angles_data[50]
self.m.pose[6] = entry['r_hip_angle_axis'][0]
self.m.pose[7] = entry['r_hip_angle_axis'][1]/2
self.m.pose[8] = entry['r_hip_angle_axis'][2]
if verbose == True: print 'r hip', self.m.pose[6:9]
self.m.pose[15] = entry['r_knee_angle_axis'][0]
self.m.pose[16] = entry['r_hip_angle_axis'][1]/2
if verbose == True: print 'r knee', self.m.pose[15:18]
self.m.pose[3] = entry['l_hip_angle_axis'][0]
self.m.pose[4] = entry['l_hip_angle_axis'][1]/2
self.m.pose[5] = entry['l_hip_angle_axis'][2]
if verbose == True: print 'l hip', self.m.pose[3:6]
self.m.pose[12] = entry['l_knee_angle_axis'][0]
self.m.pose[13] = entry['l_hip_angle_axis'][1]/2
if verbose == True: print 'l knee', self.m.pose[12:15]
self.m.pose[51] = entry['r_shoulder_angle_axis'][0]*2/3
self.m.pose[52] = entry['r_shoulder_angle_axis'][1]*2/3
self.m.pose[53] = entry['r_shoulder_angle_axis'][2]*2/3
self.m.pose[42] = entry['r_shoulder_angle_axis'][0]*1/3
self.m.pose[43] = entry['r_shoulder_angle_axis'][1]*1/3
self.m.pose[44] = entry['r_shoulder_angle_axis'][2]*1/3
if verbose == True: print 'r shoulder', self.m.pose[51:54] + self.m.pose[42:45]
self.m.pose[58] = entry['r_elbow_angle_axis'][1]
if verbose == True: print 'r elbow', self.m.pose[57:60]
self.m.pose[48] = entry['l_shoulder_angle_axis'][0]*2/3
self.m.pose[49] = entry['l_shoulder_angle_axis'][1]*2/3
self.m.pose[50] = entry['l_shoulder_angle_axis'][2]*2/3
self.m.pose[39] = entry['l_shoulder_angle_axis'][0]*1/3
self.m.pose[40] = entry['l_shoulder_angle_axis'][1]*1/3
self.m.pose[41] = entry['l_shoulder_angle_axis'][2]*1/3
if verbose == True: print 'l shoulder', self.m.pose[48:51] + self.m.pose[39:42]
self.m.pose[55] = entry['l_elbow_angle_axis'][1]
if verbose == True: print 'l elbow', self.m.pose[54:57]
def map_random_selection_to_smpl_angles(self, alter_angles):
if alter_angles == True:
selection_r_leg = ProcessYashData().sample_angles('r_leg')
self.m.pose[6] = selection_r_leg['rG_ext']
self.m.pose[7] = selection_r_leg['rG_yaw']#/2
self.m.pose[8] = selection_r_leg['rG_abd']
self.m.pose[15] = selection_r_leg['rK']
#self.m.pose[16] = selection_r_leg['rG_yaw']/2
selection_l_leg = ProcessYashData().sample_angles('l_leg')
self.m.pose[3] = selection_l_leg['lG_ext']
self.m.pose[4] = selection_l_leg['lG_yaw']#/2
self.m.pose[5] = selection_l_leg['lG_abd']
self.m.pose[12] = selection_l_leg['lK']
#self.m.pose[13] = selection_l_leg['lG_yaw']/2
selection_r_arm = ProcessYashData().sample_angles('r_arm')
self.m.pose[51] = selection_r_arm['rS_roll']*2/3
self.m.pose[52] = selection_r_arm['rS_yaw']*2/3
self.m.pose[53] = selection_r_arm['rS_pitch']*2/3
self.m.pose[42] = selection_r_arm['rS_roll']*1/3
self.m.pose[43] = selection_r_arm['rS_yaw']*1/3
self.m.pose[44] = selection_r_arm['rS_pitch']*1/3
self.m.pose[58] = selection_r_arm['rE']
selection_l_arm = ProcessYashData().sample_angles('l_arm')
self.m.pose[48] = selection_l_arm['lS_roll']*2/3
self.m.pose[49] = selection_l_arm['lS_yaw']*2/3
self.m.pose[50] = selection_l_arm['lS_pitch']*2/3
self.m.pose[39] = selection_l_arm['lS_roll']*1/3
self.m.pose[40] = selection_l_arm['lS_yaw']*1/3
self.m.pose[41] = selection_l_arm['lS_pitch']*1/3
self.m.pose[55] = selection_l_arm['lE']
#self.m.pose[51] = selection_r
from capsule_body import get_capsules, joint2name, rots0
capsules = get_capsules(self.m)
joint2name = joint2name
rots0 = rots0
print len(capsules)
#put these capsules into dart based on these angles. Make Dart joints only as necessary.
#Use the positions found in dart to update positions in FleX. Do not use angles in Flex
#repeat: do not need a forward kinematics model in FleX! Just need the capsule positions and radii. Can potentially get rotation from the Capsule end positions.
#Find IK solution at the very end.
return self.m, capsules, joint2name, rots0
if __name__ == "__main__":
generator = GeneratePose(sampling = "UNIFORM", sigma = 0, one_side_range = 0)
libRender.standard_render(generator.m)
#generator.ax = plt.figure().add_subplot(111, projection='3d')
#generator.solve_ik_tree_smpl()
posture = "lay"
generator.save_yash_data_with_angles(posture)
#generator.map_euler_angles_to_axis_angle()
#generator.check_found_limits()
#processYashData = ProcessYashData()
#processYashData.map_yash_to_axis_angle(verbose=False)
#processYashData.check_found_limits()
#processYashData.get_r_leg_angles()
#m, capsules, joint2name, rots0 = generator.map_random_selection_to_smpl_angles(alter_angles = True)
#dss = dart_skel_sim.DartSkelSim(render=True, m=m, capsules=capsules, joint_names=joint2name, initial_rots=rots0)
#generator.standard_render()
#dss.run_simulation()