MCPcopy Create free account
hub / github.com/Pixel-Talk/EHM-Tracker / part_from_body

Method part_from_body

src/modules/pixie/pixie_encoder.py:156–191  ·  view source on GitHub ↗

crop part(head/left_hand/right_hand) out from body data, joints also change accordingly

(self, image, part_key, points_dict, crop_joints=None)

Source from the content-addressed store, hash-verified

154 return code_dict
155
156 def part_from_body(self, image, part_key, points_dict, crop_joints=None):
157 ''' crop part(head/left_hand/right_hand) out from body data, joints also change accordingly
158 '''
159 assert part_key in ['head', 'left_hand', 'right_hand']
160 assert 'smplx_kpt' in points_dict.keys()
161 if part_key == 'head':
162 # use face 68 kpts for cropping head image
163 indices_key = 'face'
164 elif part_key == 'left_hand':
165 indices_key = 'left_hand'
166 elif part_key == 'right_hand':
167 indices_key = 'right_hand'
168
169 # get points for cropping
170 part_indices = self.part_indices[indices_key]
171 if crop_joints is not None:
172 points_for_crop = crop_joints[:, part_indices]
173 else:
174 points_for_crop = points_dict['smplx_kpt'][:, part_indices]
175
176 # crop
177 cropper_key = 'hand' if 'hand' in part_key else part_key
178 points_scale = image.shape[-2:]
179 cropped_image, tform = self.Cropper[cropper_key].crop(
180 image,
181 points_for_crop,
182 points_scale
183 )
184 # transform points(must be normalized to [-1.1]) accordingly
185 cropped_points_dict = {}
186 for points_key in points_dict.keys():
187 points = points_dict[points_key]
188 cropped_points = self.Cropper[cropper_key].transform_points(
189 points, tform, points_scale, normalize=True)
190 cropped_points_dict[points_key] = cropped_points
191 return cropped_image, cropped_points_dict
192
193 @torch.no_grad()
194 def forward(self, image, image_hd, threthold=True, keep_local=True, copy_and_paste=False, body_only=False):

Callers 1

forwardMethod · 0.95

Calls 3

transform_pointsMethod · 0.80
keysMethod · 0.45
cropMethod · 0.45

Tested by

no test coverage detected