Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei-Chen-hub committed May 28, 2024
1 parent 2364b16 commit c1b1a56
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions mmhuman3d/data/data_converters/dynacam.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
bboxs_ = {}
for key in ['bbox_xywh']:
bboxs_[key] = []
image_path_, keypoints2d_smpl_ = [], []
image_path_, keypoints2d_smpl_, keypoints3d_smpl_ = [], [], []
meta_ = {}
for meta_key in ['principal_point', 'focal_length', 'height', 'width']:
for meta_key in ['principal_point', 'focal_length', 'height', 'width', 'track_id']:
meta_[meta_key] = []

seed = 230720
seed = 240429
size = 999

random_ids = np.random.RandomState(seed).permutation(999999)
used_id_num = 0

# prepare batch
batch_name, batch_mode = mode.split('_')

Expand Down Expand Up @@ -150,6 +153,9 @@ def convert_by_mode(self, dataset_path: str, out_path: str,

for sid in range(subject_num):

track_id = random_ids[used_id_num]
used_id_num += 1

for fid, fname in tqdm(enumerate(frame_names), desc=f'Subject {sid+1}/{subject_num}',
total=len(frame_names), position=1, leave=False):

Expand Down Expand Up @@ -212,7 +218,8 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
keypoints_3d = output['joints']
keypoints_2d_xyd = camera.transform_points_screen(keypoints_3d)
keypoints_2d = keypoints_2d_xyd[..., :2].detach().cpu().numpy()

keypoints_3d = keypoints_3d.detach().cpu().numpy()

# get bbox_xywh
bbox_xyxy = self._keypoints_to_scaled_bbox(keypoints_2d, scale=1.2)
xmin, ymin, xmax, ymax = bbox_xyxy
Expand All @@ -224,6 +231,7 @@ def convert_by_mode(self, dataset_path: str, out_path: str,

# append keypoints2d
keypoints2d_smpl_.append(keypoints_2d)
keypoints3d_smpl_.append(keypoints_3d)

# append bbox
bboxs_['bbox_xywh'].append(bbox)
Expand All @@ -239,6 +247,7 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
meta_['focal_length'].append((intrinsic[0, 0], intrinsic[1, 1]))
meta_['height'].append(height)
meta_['width'].append(width)
meta_['track_id'].append(track_id)

# visulize
# img = cv2.imread(img_path)
Expand Down Expand Up @@ -268,7 +277,7 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
smpl_[key], axis=0).reshape(self.smpl_shape[key])
human_data['smpl'] = smpl_

# keypoints2d_smplx
# keypoints2d_smpl
keypoints2d_smpl = np.concatenate(
keypoints2d_smpl_, axis=0).reshape(-1, 45, 2)
keypoints2d_smpl_conf = np.ones([keypoints2d_smpl.shape[0], 45, 1])
Expand All @@ -279,6 +288,17 @@ def convert_by_mode(self, dataset_path: str, out_path: str,
human_data['keypoints2d_smpl'] = keypoints2d_smpl
human_data['keypoints2d_smpl_mask'] = keypoints2d_smpl_mask

# keypoints3d_smpl
keypoints3d_smpl = np.concatenate(
keypoints3d_smpl_, axis=0).reshape(-1, 45, 3)
keypoints3d_smpl_conf = np.ones([keypoints3d_smpl.shape[0], 45, 1])
keypoints3d_smpl = np.concatenate(
[keypoints3d_smpl, keypoints3d_smpl_conf], axis=-1)
keypoints3d_smpl, keypoints3d_smpl_mask = \
convert_kps(keypoints3d_smpl, src='smpl_45', dst='human_data')
human_data['keypoints3d_smpl'] = keypoints3d_smpl
human_data['keypoints3d_smpl_mask'] = keypoints3d_smpl_mask

# misc
human_data['misc'] = self.misc_config
human_data['config'] = f'dynacam_{mode}'
Expand Down

0 comments on commit c1b1a56

Please sign in to comment.