carsten12 commited on
Commit
6bd4aae
·
verified ·
1 Parent(s): fcec597

Create measurement_definitions.py

Browse files
Files changed (1) hide show
  1. measurement_definitions.py +289 -0
measurement_definitions.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from landmark_definitions import *
3
+ from joint_definitions import *
4
+
5
+ STANDARD_LABELS = {
6
+ 'A': 'head circumference',
7
+ 'B': 'neck circumference',
8
+ 'C': 'shoulder to crotch height',
9
+ 'D': 'chest circumference',
10
+ 'E': 'waist circumference',
11
+ 'F': 'hip circumference',
12
+ 'G': 'wrist right circumference',
13
+ 'H': 'bicep right circumference',
14
+ 'I': 'forearm right circumference',
15
+ 'J': 'arm right length',
16
+ 'K': 'inside leg height',
17
+ 'L': 'thigh left circumference',
18
+ 'M': 'calf left circumference',
19
+ 'N': 'ankle left circumference',
20
+ 'O': 'shoulder breadth',
21
+ 'P': 'height'
22
+ }
23
+
24
+
25
+ class MeasurementType():
26
+ CIRCUMFERENCE = "circumference"
27
+ LENGTH = "length"
28
+
29
+
30
+ MEASUREMENT_TYPES = {
31
+ "height": MeasurementType.LENGTH,
32
+ "head circumference": MeasurementType.CIRCUMFERENCE,
33
+ "neck circumference": MeasurementType.CIRCUMFERENCE,
34
+ "shoulder to crotch height": MeasurementType.LENGTH,
35
+ "chest circumference": MeasurementType.CIRCUMFERENCE,
36
+ "waist circumference": MeasurementType.CIRCUMFERENCE,
37
+ "hip circumference": MeasurementType.CIRCUMFERENCE,
38
+
39
+ "wrist right circumference": MeasurementType.CIRCUMFERENCE,
40
+ "bicep right circumference": MeasurementType.CIRCUMFERENCE,
41
+ "forearm right circumference": MeasurementType.CIRCUMFERENCE,
42
+ "arm right length": MeasurementType.LENGTH,
43
+ "arm left length": MeasurementType.LENGTH,
44
+ "inside leg height": MeasurementType.LENGTH,
45
+ "thigh left circumference": MeasurementType.CIRCUMFERENCE,
46
+ "calf left circumference": MeasurementType.CIRCUMFERENCE,
47
+ "ankle left circumference": MeasurementType.CIRCUMFERENCE,
48
+ "shoulder breadth": MeasurementType.LENGTH,
49
+
50
+ "arm length (shoulder to elbow)": MeasurementType.LENGTH,
51
+ "arm length (spine to wrist)": MeasurementType.LENGTH,
52
+ "crotch height": MeasurementType.LENGTH,
53
+ "Hip circumference max height": MeasurementType.LENGTH
54
+ }
55
+
56
+ class SMPLMeasurementDefinitions():
57
+ '''
58
+ Definition of SMPL measurements.
59
+
60
+ To add a new measurement:
61
+ 1. add it to the measurement_types dict and set the type:
62
+ LENGTH or CIRCUMFERENCE
63
+ 2. depending on the type, define the measurement in LENGTHS or
64
+ CIRCUMFERENCES dict
65
+ - LENGTHS are defined using 2 landmarks - the measurement is
66
+ found with distance between landmarks
67
+ - CIRCUMFERENCES are defined with landmarks and joints - the
68
+ measurement is found by cutting the SMPL model with the
69
+ plane defined by a point (landmark point) and normal (
70
+ vector connecting the two joints)
71
+ 3. If the body part is a CIRCUMFERENCE, a possible issue that arises is
72
+ that the plane cutting results in multiple body part slices. To alleviate
73
+ that, define the body part where the measurement should be located in
74
+ CIRCUMFERENCE_TO_BODYPARTS dict. This way, only slice in that body part is
75
+ used for finding the measurement. The body parts are defined by the SMPL
76
+ face segmentation.
77
+ '''
78
+
79
+ LENGTHS = {"height":
80
+ (SMPL_LANDMARK_INDICES["HEAD_TOP"],
81
+ SMPL_LANDMARK_INDICES["HEELS"]
82
+ ),
83
+ "shoulder to crotch height":
84
+ (SMPL_LANDMARK_INDICES["SHOULDER_TOP"],
85
+ SMPL_LANDMARK_INDICES["INSEAM_POINT"]
86
+ ),
87
+ "arm left length":
88
+ (SMPL_LANDMARK_INDICES["LEFT_SHOULDER"],
89
+ SMPL_LANDMARK_INDICES["LEFT_WRIST"]
90
+ ),
91
+ "arm right length":
92
+ (SMPL_LANDMARK_INDICES["RIGHT_SHOULDER"],
93
+ SMPL_LANDMARK_INDICES["RIGHT_WRIST"]
94
+ ),
95
+ "inside leg height":
96
+ (SMPL_LANDMARK_INDICES["LOW_LEFT_HIP"],
97
+ SMPL_LANDMARK_INDICES["LEFT_ANKLE"]
98
+ ),
99
+ "shoulder breadth":
100
+ (SMPL_LANDMARK_INDICES["LEFT_SHOULDER"],
101
+ SMPL_LANDMARK_INDICES["RIGHT_SHOULDER"]
102
+ ),
103
+ "arm length (shoulder to elbow)":
104
+ (
105
+ # SMPL_LANDMARK_INDICES["LEFT_SHOULDER"],
106
+ # SMPL_LANDMARK_INDICES["LEFT_ELBOW"]
107
+ SMPL_LANDMARK_INDICES["Rt. Acromion"],
108
+ SMPL_LANDMARK_INDICES["Rt. Humeral Lateral Epicn"]
109
+ ),
110
+ "crotch height":
111
+ (SMPL_LANDMARK_INDICES["CROTCH"],
112
+ SMPL_LANDMARK_INDICES["HEELS"]
113
+ ),
114
+ "Hip circumference max height":
115
+ (SMPL_LANDMARK_INDICES["PUBIC_BONE"],
116
+ SMPL_LANDMARK_INDICES["HEELS"]
117
+ ),
118
+ # FIXME: implement geodesic distance for this measurement
119
+ "arm length (spine to wrist)":
120
+ (
121
+ # SMPL_LANDMARK_INDICES["SHOULDER_TOP"],
122
+ # SMPL_LANDMARK_INDICES["LEFT_WRIST"]
123
+ SMPL_LANDMARK_INDICES["Cervicale"],
124
+ SMPL_LANDMARK_INDICES["Rt. Acromion"],
125
+ SMPL_LANDMARK_INDICES["Rt. Humeral Lateral Epicn"],
126
+ SMPL_LANDMARK_INDICES["Rt. Ulnar Styloid"]
127
+ ),
128
+ }
129
+
130
+ # defined with landmarks and joints
131
+ # landmarks are defined with indices of the smpl model points
132
+ # normals are defined with joint names of the smpl model
133
+ CIRCUMFERENCES = {
134
+ "head circumference":{"LANDMARKS":["HEAD_LEFT_TEMPLE"],
135
+ "JOINTS":["pelvis","spine3"]},
136
+
137
+ "neck circumference":{"LANDMARKS":["NECK_ADAM_APPLE"],
138
+ "JOINTS":["spine2","head"]},
139
+
140
+ "chest circumference":{"LANDMARKS":["LEFT_NIPPLE","RIGHT_NIPPLE"],
141
+ "JOINTS":["pelvis","spine3"]},
142
+
143
+ "waist circumference":{"LANDMARKS":["BELLY_BUTTON","BACK_BELLY_BUTTON"],
144
+ "JOINTS":["pelvis","spine3"]},
145
+
146
+ "hip circumference":{"LANDMARKS":["PUBIC_BONE"],
147
+ "JOINTS":["pelvis","spine3"]},
148
+
149
+ "wrist right circumference":{"LANDMARKS":["RIGHT_WRIST"],
150
+ "JOINTS":["right_wrist","right_hand"]},
151
+
152
+ "bicep right circumference":{"LANDMARKS":["RIGHT_BICEP"],
153
+ "JOINTS":["right_shoulder","right_elbow"]},
154
+
155
+ "forearm right circumference":{"LANDMARKS":["RIGHT_FOREARM"],
156
+ "JOINTS":["right_elbow","right_wrist"]},
157
+
158
+ "thigh left circumference":{"LANDMARKS":["LEFT_THIGH"],
159
+ "JOINTS":["pelvis","spine3"]},
160
+
161
+ "calf left circumference":{"LANDMARKS":["LEFT_CALF"],
162
+ "JOINTS":["pelvis","spine3"]},
163
+
164
+ "ankle left circumference":{"LANDMARKS":["LEFT_ANKLE"],
165
+ "JOINTS":["pelvis","spine3"]},
166
+
167
+ }
168
+
169
+ possible_measurements = list(LENGTHS.keys()) + list(CIRCUMFERENCES.keys())
170
+
171
+ CIRCUMFERENCE_TO_BODYPARTS = {
172
+ "head circumference": "head",
173
+ "neck circumference":"neck",
174
+ "chest circumference":["spine1","spine2"],
175
+ "waist circumference":["hips","spine"],
176
+ "hip circumference":"hips",
177
+ "wrist right circumference":["rightHand","rightForeArm"],
178
+ "bicep right circumference":"rightArm",
179
+ "forearm right circumference":"rightForeArm",
180
+ "thigh left circumference": "leftUpLeg",
181
+ "calf left circumference": "leftLeg",
182
+ "ankle left circumference": "leftLeg",
183
+ }
184
+
185
+
186
+
187
+ class SMPLXMeasurementDefinitions():
188
+ '''
189
+ Definition of SMPLX measurements.
190
+
191
+ To add a new measurement:
192
+ 1. add it to the measurement_types dict and set the type:
193
+ LENGTH or CIRCUMFERENCE
194
+ 2. depending on the type, define the measurement in LENGTHS or
195
+ CIRCUMFERENCES dict
196
+ - LENGTHS are defined using 2 landmarks - the measurement is
197
+ found with distance between landmarks
198
+ - CIRCUMFERENCES are defined with landmarks and joints - the
199
+ measurement is found by cutting the SMPLX model with the
200
+ plane defined by a point (landmark point) and normal (
201
+ vector connecting the two joints)
202
+ 3. If the body part is a CIRCUMFERENCE, a possible issue that arises is
203
+ that the plane cutting results in multiple body part slices. To alleviate
204
+ that, define the body part where the measurement should be located in
205
+ CIRCUMFERENCE_TO_BODYPARTS dict. This way, only slice in that body part is
206
+ used for finding the measurement. The body parts are defined by the SMPL
207
+ face segmentation.
208
+ '''
209
+
210
+ LENGTHS = {"height":
211
+ (SMPLX_LANDMARK_INDICES["HEAD_TOP"],
212
+ SMPLX_LANDMARK_INDICES["HEELS"]
213
+ ),
214
+ "shoulder to crotch height":
215
+ (SMPLX_LANDMARK_INDICES["SHOULDER_TOP"],
216
+ SMPLX_LANDMARK_INDICES["INSEAM_POINT"]
217
+ ),
218
+ "arm left length":
219
+ (SMPLX_LANDMARK_INDICES["LEFT_SHOULDER"],
220
+ SMPLX_LANDMARK_INDICES["LEFT_WRIST"]
221
+ ),
222
+ "arm right length":
223
+ (SMPLX_LANDMARK_INDICES["RIGHT_SHOULDER"],
224
+ SMPLX_LANDMARK_INDICES["RIGHT_WRIST"]
225
+ ),
226
+ "inside leg height":
227
+ (SMPLX_LANDMARK_INDICES["LOW_LEFT_HIP"],
228
+ SMPLX_LANDMARK_INDICES["LEFT_ANKLE"]
229
+ ),
230
+ "shoulder breadth":
231
+ (SMPLX_LANDMARK_INDICES["LEFT_SHOULDER"],
232
+ SMPLX_LANDMARK_INDICES["RIGHT_SHOULDER"]
233
+ ),
234
+ }
235
+
236
+ # defined with landmarks and joints
237
+ # landmarks are defined with indices of the smpl model points
238
+ # normals are defined with joint names of the smpl model
239
+ CIRCUMFERENCES = {
240
+ "head circumference":{"LANDMARKS":["HEAD_LEFT_TEMPLE"],
241
+ "JOINTS":["pelvis","spine3"]},
242
+
243
+ "neck circumference":{"LANDMARKS":["NECK_ADAM_APPLE"],
244
+ "JOINTS":["spine1","spine3"]},
245
+
246
+ "chest circumference":{"LANDMARKS":["LEFT_NIPPLE","RIGHT_NIPPLE"],
247
+ "JOINTS":["pelvis","spine3"]},
248
+
249
+ "waist circumference":{"LANDMARKS":["BELLY_BUTTON","BACK_BELLY_BUTTON"],
250
+ "JOINTS":["pelvis","spine3"]},
251
+
252
+ "hip circumference":{"LANDMARKS":["PUBIC_BONE"],
253
+ "JOINTS":["pelvis","spine3"]},
254
+
255
+ "wrist right circumference":{"LANDMARKS":["RIGHT_WRIST"],
256
+ "JOINTS":["right_wrist","right_elbow"]}, # different from SMPL
257
+
258
+ "bicep right circumference":{"LANDMARKS":["RIGHT_BICEP"],
259
+ "JOINTS":["right_shoulder","right_elbow"]},
260
+
261
+ "forearm right circumference":{"LANDMARKS":["RIGHT_FOREARM"],
262
+ "JOINTS":["right_elbow","right_wrist"]},
263
+
264
+ "thigh left circumference":{"LANDMARKS":["LEFT_THIGH"],
265
+ "JOINTS":["pelvis","spine3"]},
266
+
267
+ "calf left circumference":{"LANDMARKS":["LEFT_CALF"],
268
+ "JOINTS":["pelvis","spine3"]},
269
+
270
+ "ankle left circumference":{"LANDMARKS":["LEFT_ANKLE"],
271
+ "JOINTS":["pelvis","spine3"]},
272
+
273
+ }
274
+
275
+ possible_measurements = list(LENGTHS.keys()) + list(CIRCUMFERENCES.keys())
276
+
277
+ CIRCUMFERENCE_TO_BODYPARTS = {
278
+ "head circumference": "head",
279
+ "neck circumference":"neck",
280
+ "chest circumference":["spine1","spine2"],
281
+ "waist circumference":["hips","spine"],
282
+ "hip circumference":"hips",
283
+ "wrist right circumference":["rightHand","rightForeArm"],
284
+ "bicep right circumference":"rightArm",
285
+ "forearm right circumference":"rightForeArm",
286
+ "thigh left circumference": "leftUpLeg",
287
+ "calf left circumference": "leftLeg",
288
+ "ankle left circumference": "leftLeg",
289
+ }