MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / AAPoseMeta

Class AAPoseMeta

tools/preprocess/pose2d_utils.py:42–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42class AAPoseMeta:
43 def __init__(self, meta=None, kp2ds=None):
44 self.image_id = ""
45 self.height = 0
46 self.width = 0
47
48 self.kps_body: np.ndarray = None
49 self.kps_lhand: np.ndarray = None
50 self.kps_rhand: np.ndarray = None
51 self.kps_face: np.ndarray = None
52 self.kps_body_p: np.ndarray = None
53 self.kps_lhand_p: np.ndarray = None
54 self.kps_rhand_p: np.ndarray = None
55 self.kps_face_p: np.ndarray = None
56
57 if meta is not None:
58 self.load_from_meta(meta)
59 elif kp2ds is not None:
60 self.load_from_kp2ds(kp2ds)
61
62 def is_valid(self, kp, p, threshold):
63 x, y = kp
64 if x < 0 or y < 0 or x > self.width or y > self.height or p < threshold:
65 return False
66 else:
67 return True
68
69 def get_bbox(self, kp, kp_p, threshold=0.5):
70 kps = kp[kp_p > threshold]
71 if kps.size == 0:
72 return 0, 0, 0, 0
73 x0, y0 = kps.min(axis=0)
74 x1, y1 = kps.max(axis=0)
75 return x0, y0, x1, y1
76
77 def crop(self, x0, y0, x1, y1):
78 all_kps = [self.kps_body, self.kps_lhand, self.kps_rhand, self.kps_face]
79 for kps in all_kps:
80 if kps is not None:
81 kps[:, 0] -= x0
82 kps[:, 1] -= y0
83 self.width = x1 - x0
84 self.height = y1 - y0
85 return self
86
87 def resize(self, width, height):
88 scale_x = width / self.width
89 scale_y = height / self.height
90 all_kps = [self.kps_body, self.kps_lhand, self.kps_rhand, self.kps_face]
91 for kps in all_kps:
92 if kps is not None:
93 kps[:, 0] *= scale_x
94 kps[:, 1] *= scale_y
95 self.width = width
96 self.height = height
97 return self
98
99 def get_kps_body_with_p(self, normalize=False):

Callers 7

get_retarget_poseFunction · 0.90
from_kps_faceMethod · 0.85
from_kps_bodyMethod · 0.85
from_humanapi_metaMethod · 0.85
load_from_kp2dsMethod · 0.85
from_dwposeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected