Delete old py code.

This commit is contained in:
Daniel
2024-09-26 12:10:05 +02:00
parent d2efb66767
commit 3318afc3f1
3 changed files with 0 additions and 679 deletions

View File

@ -188,111 +188,6 @@ def load_labels(dataset: dict):
# ==================================================================================================
def add_extra_joints(poses3D, poses2D, joint_names_3d):
# Update "head" joint as average of "ear" joints
idx_h = joint_names_3d.index("head")
idx_el = joint_names_3d.index("ear_left")
idx_er = joint_names_3d.index("ear_right")
for i in range(len(poses3D)):
if poses3D[i, idx_h, 3] == 0:
ear_left = poses3D[i, idx_el]
ear_right = poses3D[i, idx_er]
if ear_left[3] > 0.1 and ear_right[3] > 0.1:
head = (ear_left + ear_right) / 2
head[3] = min(ear_left[3], ear_right[3])
poses3D[i, idx_h] = head
for j in range(len(poses2D)):
ear_left = poses2D[j][i, idx_el]
ear_right = poses2D[j][i, idx_er]
if ear_left[2] > 0.1 and ear_right[2] > 0.1:
head = (ear_left + ear_right) / 2
head[2] = min(ear_left[2], ear_right[2])
poses2D[j][i, idx_h] = head
return poses3D, poses2D
# ==================================================================================================
def add_missing_joints(poses3D, joint_names_3d):
"""Replace missing joints with their nearest adjacent joints"""
adjacents = {
"hip_right": ["hip_middle", "hip_left"],
"hip_left": ["hip_middle", "hip_right"],
"knee_right": ["hip_right", "knee_left"],
"knee_left": ["hip_left", "knee_right"],
"ankle_right": ["knee_right", "ankle_left"],
"ankle_left": ["knee_left", "ankle_right"],
"shoulder_right": ["shoulder_middle", "shoulder_left"],
"shoulder_left": ["shoulder_middle", "shoulder_right"],
"elbow_right": ["shoulder_right", "hip_right"],
"elbow_left": ["shoulder_left", "hip_left"],
"wrist_right": ["elbow_right"],
"wrist_left": ["elbow_left"],
"nose": ["shoulder_middle", "shoulder_right", "shoulder_left"],
"head": ["shoulder_middle", "shoulder_right", "shoulder_left"],
"foot_*_left_*": ["ankle_left"],
"foot_*_right_*": ["ankle_right"],
"face_*": ["nose"],
"hand_*_left_*": ["wrist_left"],
"hand_*_right_*": ["wrist_right"],
}
for i in range(len(poses3D)):
valid_joints = np.where(poses3D[i, :, 3] > 0.1)[0]
if len(valid_joints) == 0:
continue
body_center = np.mean(poses3D[i, valid_joints, :3], axis=0)
for j in range(len(joint_names_3d)):
adname = ""
if joint_names_3d[j][0:5] == "foot_" and "_left" in joint_names_3d[j]:
adname = "foot_*_left_*"
elif joint_names_3d[j][0:5] == "foot_" and "_right" in joint_names_3d[j]:
adname = "foot_*_right_*"
elif joint_names_3d[j][0:5] == "face_":
adname = "face_*"
elif joint_names_3d[j][0:5] == "hand_" and "_left" in joint_names_3d[j]:
adname = "hand_*_left_*"
elif joint_names_3d[j][0:5] == "hand_" and "_right" in joint_names_3d[j]:
adname = "hand_*_right_*"
elif joint_names_3d[j] in adjacents:
adname = joint_names_3d[j]
if adname == "":
continue
if poses3D[i, j, 3] == 0:
if joint_names_3d[j] in adjacents or joint_names_3d[j][0:5] in [
"foot_",
"face_",
"hand_",
]:
adjacent_joints = [
poses3D[i, joint_names_3d.index(a), :]
for a in adjacents[adname]
]
adjacent_joints = [a[0:3] for a in adjacent_joints if a[3] > 0.1]
if len(adjacent_joints) > 0:
poses3D[i, j, :3] = np.mean(adjacent_joints, axis=0)
else:
poses3D[i, j, :3] = body_center
else:
poses3D[i, j, :3] = body_center
poses3D[i, j, 3] = 0.1
return poses3D
# ==================================================================================================
def main():
global joint_names_3d, eval_joints