Delete old py code.
This commit is contained in:
@ -228,124 +228,6 @@ def load_image(path: str):
|
||||
# ==================================================================================================
|
||||
|
||||
|
||||
def filter_poses(poses3D, poses2D, roomparams, joint_names, drop_few_limbs=True):
|
||||
drop = []
|
||||
for i, pose in enumerate(poses3D):
|
||||
pose = np.array(pose)
|
||||
valid_joints = [j for j in pose if j[-1] > 0.1]
|
||||
|
||||
# Drop persons with too few joints
|
||||
if np.sum(pose[..., -1] > 0.1) < 5:
|
||||
drop.append(i)
|
||||
continue
|
||||
|
||||
# Drop too large or too small persons
|
||||
mins = np.min(valid_joints, axis=0)
|
||||
maxs = np.max(valid_joints, axis=0)
|
||||
diff = maxs - mins
|
||||
if any(((d > 2.3) for d in diff)):
|
||||
drop.append(i)
|
||||
continue
|
||||
if all(((d < 0.3) for d in diff)):
|
||||
drop.append(i)
|
||||
continue
|
||||
if (
|
||||
(diff[0] < 0.2 and diff[1] < 0.2)
|
||||
or (diff[1] < 0.2 and diff[2] < 0.2)
|
||||
or (diff[2] < 0.2 and diff[0] < 0.2)
|
||||
):
|
||||
drop.append(i)
|
||||
continue
|
||||
|
||||
# Drop persons outside room
|
||||
mean = np.mean(valid_joints, axis=0)
|
||||
mins = np.min(valid_joints, axis=0)
|
||||
maxs = np.max(valid_joints, axis=0)
|
||||
rsize = [r / 2 for r in roomparams["room_size"]]
|
||||
rcent = roomparams["room_center"]
|
||||
if any(
|
||||
(
|
||||
# Center of mass outside room
|
||||
mean[j] > rsize[j] + rcent[j] or mean[j] < -rsize[j] + rcent[j]
|
||||
for j in range(3)
|
||||
)
|
||||
) or any(
|
||||
(
|
||||
# One limb more than 10cm outside room
|
||||
maxs[j] > rsize[j] + rcent[j] + 0.1
|
||||
or mins[j] < -rsize[j] + rcent[j] - 0.1
|
||||
for j in range(3)
|
||||
)
|
||||
):
|
||||
drop.append(i)
|
||||
continue
|
||||
|
||||
if drop_few_limbs:
|
||||
# Drop persons with less than 3 limbs
|
||||
found_limbs = 0
|
||||
for limb in main_limbs:
|
||||
start_idx = joint_names.index(limb[0])
|
||||
end_idx = joint_names.index(limb[1])
|
||||
if pose[start_idx, -1] > 0.1 and pose[end_idx, -1] > 0.1:
|
||||
found_limbs += 1
|
||||
if found_limbs < 3:
|
||||
drop.append(i)
|
||||
continue
|
||||
|
||||
# Drop persons with too small or high average limb length
|
||||
total_length = 0
|
||||
total_limbs = 0
|
||||
for limb in main_limbs:
|
||||
start_idx = joint_names.index(limb[0])
|
||||
end_idx = joint_names.index(limb[1])
|
||||
if pose[start_idx, -1] < 0.1 or pose[end_idx, -1] < 0.1:
|
||||
continue
|
||||
limb_length = np.linalg.norm(pose[end_idx, :3] - pose[start_idx, :3])
|
||||
total_length += limb_length
|
||||
total_limbs += 1
|
||||
if total_limbs == 0:
|
||||
drop.append(i)
|
||||
continue
|
||||
average_length = total_length / total_limbs
|
||||
if average_length < 0.1:
|
||||
drop.append(i)
|
||||
continue
|
||||
if total_limbs > 4 and average_length > 0.5:
|
||||
drop.append(i)
|
||||
continue
|
||||
|
||||
new_poses3D = []
|
||||
new_poses2D = [[] for _ in range(len(poses2D))]
|
||||
for i in range(len(poses3D)):
|
||||
if len(poses3D[i]) != len(joint_names):
|
||||
# Sometimes some joints of a poor detection are missing
|
||||
continue
|
||||
|
||||
if i not in drop:
|
||||
new_poses3D.append(poses3D[i])
|
||||
for j in range(len(poses2D)):
|
||||
new_poses2D[j].append(poses2D[j][i])
|
||||
else:
|
||||
new_pose = np.array(poses3D[i])
|
||||
new_pose[..., -1] = 0.001
|
||||
new_poses3D.append(new_pose)
|
||||
for j in range(len(poses2D)):
|
||||
new_pose = np.array(poses2D[j][i])
|
||||
new_pose[..., -1] = 0.001
|
||||
new_poses2D[j].append(new_pose)
|
||||
|
||||
new_poses3D = np.array(new_poses3D)
|
||||
new_poses2D = np.array(new_poses2D)
|
||||
if new_poses3D.size == 0:
|
||||
new_poses3D = np.zeros([1, len(joint_names), 4])
|
||||
new_poses2D = np.zeros([len(poses2D), 1, len(joint_names), 3])
|
||||
|
||||
return new_poses3D, new_poses2D
|
||||
|
||||
|
||||
# ==================================================================================================
|
||||
|
||||
|
||||
def update_keypoints(poses_2d: list, joint_names: List[str]) -> list:
|
||||
new_views = []
|
||||
for view in poses_2d:
|
||||
|
||||
Reference in New Issue
Block a user