MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / TopDownAffine

Class TopDownAffine

PATH/core/data/transforms/pose_transforms.py:370–434  ·  view source on GitHub ↗

Affine transform the image to make input. Required keys:'img', 'joints_3d', 'joints_3d_visible', 'ann_info','scale', 'rotation' and 'center'. Modified keys:'img', 'joints_3d', and 'joints_3d_visible'. Args: use_udp (bool): To use unbiased data processing. Paper re

Source from the content-addressed store, hash-verified

368
369
370class TopDownAffine:
371 """Affine transform the image to make input.
372 Required keys:'img', 'joints_3d', 'joints_3d_visible', 'ann_info','scale',
373 'rotation' and 'center'.
374 Modified keys:'img', 'joints_3d', and 'joints_3d_visible'.
375 Args:
376 use_udp (bool): To use unbiased data processing.
377 Paper ref: Huang et al. The Devil is in the Details: Delving into
378 Unbiased Data Processing for Human Pose Estimation (CVPR 2020).
379 """
380
381 def __init__(self, use_udp=False):
382 self.use_udp = use_udp
383
384 def __call__(self, results):
385 image_size = results['ann_info']['image_size']
386
387 img = results['image']
388 joints_3d = results['joints_3d']
389 joints_3d_visible = results['joints_3d_visible']
390 c = results['center']
391 s = results['scale']
392 r = results['rotation']
393
394 if self.use_udp:
395 trans = get_warp_matrix(r, c * 2.0, image_size - 1.0, s * 200.0)
396 if not isinstance(img, list):
397 img = cv2.warpAffine(
398 img,
399 trans, (int(image_size[0]), int(image_size[1])),
400 flags=cv2.INTER_LINEAR)
401 else:
402 img = [
403 cv2.warpAffine(
404 i,
405 trans, (int(image_size[0]), int(image_size[1])),
406 flags=cv2.INTER_LINEAR) for i in img
407 ]
408
409 joints_3d[:, 0:2] = \
410 warp_affine_joints(joints_3d[:, 0:2].copy(), trans)
411
412 else:
413 trans = get_affine_transform(c, s, r, image_size)
414 if not isinstance(img, list):
415 img = cv2.warpAffine(
416 img,
417 trans, (int(image_size[0]), int(image_size[1])),
418 flags=cv2.INTER_LINEAR)
419 else:
420 img = [
421 cv2.warpAffine(
422 i,
423 trans, (int(image_size[0]), int(image_size[1])),
424 flags=cv2.INTER_LINEAR) for i in img
425 ]
426 for i in range(results['ann_info']['num_joints']):
427 if joints_3d_visible[i, 0] > 0.0:

Callers 4

__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected