Skip to content

Commit df3b655

Browse files
author
WC
committed
update hands 241028
1 parent 2f7a5d3 commit df3b655

File tree

5 files changed

+106
-30
lines changed

5 files changed

+106
-30
lines changed

mmhuman3d/core/conventions/keypoints_mapping/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
crowdpose,
1313
face3d,
1414
flame,
15+
freihand,
1516
gta,
1617
h36m,
1718
human_data,
@@ -82,6 +83,7 @@
8283
'mediapipe_whole_body': mediapipe.MP_WHOLE_BODY_KEYPOINTS,
8384
'mediapipe_body': mediapipe.MP_BODY_KEYPOINTS,
8485
'interhand': interhand.INTERHAND_KEYPOINTS,
86+
'freihand': freihand.FREIHAND_KEYPOINTS,
8587
}
8688

8789
__KEYPOINTS_MAPPING_CACHE__ = defaultdict(dict)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FREIHAND_KEYPOINTS = [
2+
'right_wrist',
3+
'right_thumb_1',
4+
'right_thumb_2',
5+
'right_thumb_3',
6+
'right_thumb',
7+
'right_index_1',
8+
'right_index_2',
9+
'right_index_3',
10+
'right_index',
11+
'right_middle_1',
12+
'right_middle_2',
13+
'right_middle_3',
14+
'right_middle',
15+
'right_ring_1',
16+
'right_ring_2',
17+
'right_ring_3',
18+
'right_ring',
19+
'right_pinky_1',
20+
'right_pinky_2',
21+
'right_pinky_3',
22+
'right_pinky',
23+
]

mmhuman3d/core/conventions/keypoints_mapping/interhand.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
INTERHAND_KEYPOINTS = [
2+
'right_thumb', # 指尖
3+
'right_thumb_3',
4+
'right_thumb_2',
5+
'right_thumb_1',
6+
'right_index',
27
'right_index_3',
38
'right_index_2',
49
'right_index_1',
5-
'right_index',
6-
'right_thumb_3', # 指尖
7-
'right_thumb_2',
8-
'right_thumb_1',
9-
'right_thumb',
10+
'right_middle',
1011
'right_middle_3',
1112
'right_middle_2',
1213
'right_middle_1',
13-
'right_middle',
14+
'right_ring',
1415
'right_ring_3',
1516
'right_ring_2',
1617
'right_ring_1',
17-
'right_ring',
18+
'right_pinky',
1819
'right_pinky_3',
1920
'right_pinky_2',
2021
'right_pinky_1',
21-
'right_pinky',
2222
'right_wrist',
23-
'left_index_3',
24-
'left_index_2',
25-
'left_index_1',
26-
'left_index',
23+
'left_thumb',
2724
'left_thumb_3',
2825
'left_thumb_2',
2926
'left_thumb_1',
30-
'left_thumb',
27+
'left_index',
28+
'left_index_3',
29+
'left_index_2',
30+
'left_index_1',
31+
'left_middle',
3132
'left_middle_3',
3233
'left_middle_2',
3334
'left_middle_1',
34-
'left_middle',
35+
'left_ring',
3536
'left_ring_3',
3637
'left_ring_2',
3738
'left_ring_1',
38-
'left_ring',
39+
'left_pinky',
3940
'left_pinky_3',
4041
'left_pinky_2',
4142
'left_pinky_1',
42-
'left_pinky',
4343
'left_wrist'
4444
]
4545

mmhuman3d/data/data_converters/freihand.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def convert_by_mode(self,
8181
stored in HumanData() format
8282
"""
8383

84-
seed = '230828'
84+
seed = '241024'
8585

8686

8787
# use HumanData to store all data
@@ -160,13 +160,37 @@ def convert_by_mode(self,
160160
kps3d = xyz[index % num_green_bg]
161161
kps3d = np.hstack([kps3d, np.ones([kps3d.shape[0], 1])])
162162
keypoints3d.append(kps3d)
163+
164+
165+
# # test overlay j2d
166+
# import cv2
167+
# img = cv2.imread(f'{dataset_path}/{img_path}')
168+
# # resize to 3x resolution
169+
# scale = 5
170+
# img = cv2.resize(img, (224*scale, 224*scale))
171+
172+
# j2d_orig = kps2d.reshape(-1, 3)
173+
# for i in range(len(j2d_orig)):
174+
# if j2d_orig[i, 2] == 0:
175+
# continue
176+
# # draw kps
177+
# cv2.circle(img, (int(j2d_orig[i,0])*scale, int(j2d_orig[i,1])*scale), 3, (0,0,255), -1)
178+
# # draw index i
179+
# cv2.putText(img, str(i), (int(j2d_orig[i,0])*scale, int(j2d_orig[i,1])*scale), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 1, cv2.LINE_AA)
180+
181+
# pass
182+
# # write image
183+
# os.makedirs(f'/mnt/AFS_weichen/mmhuman3d/test_area', exist_ok=True)
184+
# # cv2.imwrite(f'/mnt/AFS_weichen/mmhuman3d/test_area/{seq_name}_{frame_idx}_{hand_type}.jpg', img)
185+
# cv2.imwrite(f'/mnt/AFS_weichen/mmhuman3d/test_area/smplx_hands.jpg', img)
186+
# return
163187

164188
keypoints2d = np.array(keypoints2d)
165189
keypoints2d, keypoints2d_mask = convert_kps(
166-
keypoints2d, src='mano', dst='human_data')
190+
keypoints2d, src='freihand', dst='human_data')
167191
keypoints3d = np.array(keypoints3d)
168192
keypoints3d, keypoints3d_mask = convert_kps(
169-
keypoints3d, src='mano', dst='human_data')
193+
keypoints3d, src='freihand', dst='human_data')
170194

171195
# smplx['global_orient'] = np.array(smplx['global_orient']).reshape(-1, 3)
172196
# smplx['betas'] = np.array(smplx['betas'])

mmhuman3d/data/data_converters/interhand26m.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
183183
# use HumanData to store the data
184184
human_data = HumanData()
185185

186-
seed = '230828'
186+
seed = '141017'
187187
size = 999999
188188

189189
# initialize
@@ -197,12 +197,14 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
197197
image_path_, keypoints2d_smplx_ = [], []
198198
keypoints3d_smplx_ = []
199199
meta_ = {}
200-
for meta_key in ['principal_point', 'focal_length']:
200+
for meta_key in ['principal_point', 'focal_length', 'right_hand_valid', 'left_hand_valid']:
201201
meta_[meta_key] = []
202202
# save mano params for vis purpose
203203
mano_ = []
204204

205205
# pdb.set_trace()
206+
207+
instance_num = 0
206208

207209
# sort by image path
208210
for seq in tqdm(
@@ -294,6 +296,9 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
294296
image_size=(height, width),
295297
)).to(self.device)
296298

299+
# mm2m
300+
j3d_c = j3d_c / 1000
301+
297302
j2d = camera.transform_points_screen(
298303
torch.tensor(j3d_c.reshape(1, -1, 3), device=self.device))
299304
j2d_orig = j2d[0, :, :2].detach().cpu().numpy()
@@ -321,29 +326,51 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
321326
hand_param[hand_type]['pose'][3:])
322327
bboxs_[f'{hand_type[0]}hand_bbox_xywh'].append(
323328
bbox_xywh + [1])
324-
325329
else:
326330
smplx_[f'{hand_type}_hand_pose'].append(
327331
np.zeros((45)).tolist())
328332
bboxs_[f'{hand_type[0]}hand_bbox_xywh'].append(
329333
bbox_xywh + [0])
330334
bboxs_['bbox_xywh'].append([0, 0, 334, 512, 1])
331335

332-
336+
right_hand_valid = True if 'right' in available_hand_types else False
337+
left_hand_valid = True if 'left' in available_hand_types else False
338+
333339
meta_['focal_length'].append(focal)
334340
meta_['principal_point'].append(princpt)
335-
341+
342+
meta_['right_hand_valid'].append(right_hand_valid)
343+
meta_['left_hand_valid'].append(left_hand_valid)
344+
336345
# append mano params
337346
mano_.append(hand_param)
347+
348+
instance_num += 1
349+
if instance_num > 20000:
350+
break
351+
352+
# j2d_mano, _ = convert_kps(j2d_orig.reshape(1, -1, 3), src='interhand', dst='smplx')
353+
# j2d_mano = j2d_orig.reshape(-1, 3)
338354

339-
# test overlay j2d
355+
# # test overlay j2d
340356
# img = cv2.imread(f'{dataset_path}/{image_path}')
357+
# j2d_orig = j2d_mano.reshape(-1, 3)
341358
# for i in range(len(j2d_orig)):
359+
# if j2d_orig[i, 2] == 0:
360+
# continue
361+
# # draw kps
342362
# cv2.circle(img, (int(j2d_orig[i,0]), int(j2d_orig[i,1])), 3, (0,0,255), -1)
363+
# # draw index i
364+
# cv2.putText(img, str(i), (int(j2d_orig[i,0]), int(j2d_orig[i,1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 1, cv2.LINE_AA)
365+
343366
# pass
344367
# # write image
345-
# os.makedirs(f'{out_path}/{mode}', exist_ok=True)
346-
# cv2.imwrite(f'{out_path}/{mode}/{seq_name}_{frame_idx}_{hand_type}.jpg', img)
368+
# os.makedirs(f'/mnt/AFS_weichen/mmhuman3d/test_area', exist_ok=True)
369+
# # cv2.imwrite(f'/mnt/AFS_weichen/mmhuman3d/test_area/{seq_name}_{frame_idx}_{hand_type}.jpg', img)
370+
# cv2.imwrite(f'/mnt/AFS_weichen/mmhuman3d/test_area/smplx_hands.jpg', img)
371+
372+
# pdb.set_trace()
373+
347374

348375
size_i = min(size, len(image_path_))
349376

@@ -372,15 +399,15 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
372399
keypoints2d_smplx = np.concatenate(
373400
keypoints2d_smplx_, axis=0).reshape(-1, 42, 3)
374401
keypoints2d_smplx, keypoints2d_smplx_mask = \
375-
convert_kps(keypoints2d_smplx, src='mano_hands', dst='human_data')
402+
convert_kps(keypoints2d_smplx, src='interhand', dst='smplx')
376403
human_data['keypoints2d_smplx'] = keypoints2d_smplx
377404
human_data['keypoints2d_smplx_mask'] = keypoints2d_smplx_mask
378405

379406
# keypoints3d_smplx
380407
keypoints3d_smplx = np.concatenate(
381408
keypoints3d_smplx_, axis=0).reshape(-1, 42, 4)
382409
keypoints3d_smplx, keypoints3d_smplx_mask = \
383-
convert_kps(keypoints3d_smplx, src='mano_hands', dst='human_data')
410+
convert_kps(keypoints3d_smplx, src='interhand', dst='smplx')
384411
human_data['keypoints3d_smplx'] = keypoints3d_smplx
385412
human_data['keypoints3d_smplx_mask'] = keypoints3d_smplx_mask
386413

@@ -394,6 +421,6 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
394421
size_i = min(len(seqs), int(size))
395422
out_file = os.path.join(
396423
out_path,
397-
f'interhand26m_{mode}_{fps_mode}_{seed}_{"{:06d}".format(size_i)}.npz'
424+
f'interhand26m_{mode}_{fps_mode}_{seed}_{"{:06d}".format(size_i)}_sample.npz'
398425
)
399426
human_data.dump(out_file)

0 commit comments

Comments
 (0)