Skip to content

Commit

Permalink
Merge pull request #311 from oarriaga/human_pose_3D
Browse files Browse the repository at this point in the history
Human pose 3 d
  • Loading branch information
proneetsharma authored Aug 28, 2023
2 parents 0be29a2 + 1ccb0ca commit 12ce71f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
8 changes: 4 additions & 4 deletions paz/backend/image/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ def draw_human_pose6D(image, rotation, translation, camaera_intrinsics):
[0, 0, 1]])
points2D = project_to_image(rotation, translation,
points3D, camaera_intrinsics)
points2D = points2D.astype(np.int)
points2D = points2D.astype(np.int32)

x = points2D[0]
y = points2D[1]
z = points2D[2]

x_hat = (x / np.linalg.norm(x) * 60).astype(np.int)
y_hat = (y / np.linalg.norm(y) * 60).astype(np.int)
z_hat = (z / np.linalg.norm(z) * 60).astype(np.int)
x_hat = (x / np.linalg.norm(x) * 60).astype(np.int32)
y_hat = (y / np.linalg.norm(y) * 60).astype(np.int32)
z_hat = (z / np.linalg.norm(z) * 60).astype(np.int32)

offset = [50, 50]
image = draw_line(image, offset, x_hat + offset,
Expand Down
2 changes: 1 addition & 1 deletion paz/backend/keypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def merge_into_mean(keypoints2D, args_to_mean):
# Returns:
keypoints2D: keypoints2D after merging
"""
keypoints = keypoints2D.copy()
keypoints = np.array(keypoints2D.copy())
for point, joints_indices in args_to_mean.items():
keypoints[:, point] = (keypoints[:, joints_indices[0]] +
keypoints[:, joints_indices[1]]) / 2
Expand Down
27 changes: 15 additions & 12 deletions paz/pipelines/keypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ def __init__(self, solver, camera_intrinsics,
args_to_joints3D=args_to_joints3D, filter=True, draw=True,
draw_pose=True):
super(EstimateHumanPose, self).__init__()
self.pose3D = []
self.pose6D = []
self.draw = draw
self.filter = filter
self.draw_pose = draw_pose
Expand All @@ -448,17 +450,18 @@ def __init__(self, solver, camera_intrinsics,

def call(self, image):
inferences2D = self.estimate_keypoints_2D(image)
keypoints2D = np.array(inferences2D['keypoints'])
keypoints2D = inferences2D['keypoints']
if self.draw:
image = inferences2D['image']
keypoints3D = self.estimate_keypoints_3D(keypoints2D)
keypoints3D = np.reshape(keypoints3D, (-1, 32, 3))
optimized_output = self.optimize(keypoints3D, keypoints2D)
joints2D, joints3D, pose3D, projection2D = optimized_output
pose6D = human_pose3D_to_pose6D(pose3D[0])
if self.draw_pose:
rotation, translation = pose6D
image = self.draw_pose6D(image, rotation, translation)
translation = ["%.2f" % item for item in translation]
image = self.draw_text(image, str(translation), (30, 30))
return self.wrap(image, keypoints2D, pose3D, pose6D)
if len(keypoints2D) > 0:
keypoints3D = self.estimate_keypoints_3D(keypoints2D)
keypoints3D = np.reshape(keypoints3D, (-1, 32, 3))
optimized_output = self.optimize(keypoints3D, keypoints2D)
joints2D, joints3D, self.pose3D, projection2D = optimized_output
self.pose6D = human_pose3D_to_pose6D(self.pose3D[0])
if self.draw_pose:
rotation, translation = self.pose6D
image = self.draw_pose6D(image, rotation, translation)
translation = ["%.2f" % item for item in translation]
image = self.draw_text(image, str(translation), (30, 30))
return self.wrap(image, keypoints2D, self.pose3D, self.pose6D)
13 changes: 6 additions & 7 deletions paz/processors/keypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from ..datasets.human36m import human_start_joints



class ProjectKeypoints(Processor):
"""Projects homogenous keypoints (4D) in the camera coordinates system into
image coordinates using a projective transformation.
Expand Down Expand Up @@ -337,16 +336,16 @@ def __init__(self, args_to_joints3D, solver, camera_intrinsics):

def call(self, keypoints3D, keypoints2D):
joints3D = filter_keypoints3D(keypoints3D, self.args_to_joints3D)
filtered_keypoints2D = self.filter_keypoints2D(keypoints2D)
root2D = filtered_keypoints2D[:, :2]
joints2D = self.filter_keypoints2D(keypoints2D)
root2D = joints2D[:, :2]
length2D, length3D = get_bones_length(
filtered_keypoints2D, keypoints3D, human_start_joints)
joints2D, keypoints3D, human_start_joints)
ratio = length3D / length2D
initial_joint_translation = initialize_translation(
root2D, self.camera_intrinsics, ratio)
joint_translation = solve_least_squares(
self.solver, compute_reprojection_error, initial_joint_translation,
joints3D, filtered_keypoints2D, self.camera_intrinsics)
optimized_poses3D, projected_points2D = compute_optimized_pose3D(
joints3D, joints2D, self.camera_intrinsics)
optimized_poses3D, projection2D = compute_optimized_pose3D(
keypoints3D, joint_translation, self.camera_intrinsics)
return filtered_keypoints2D, joints3D, optimized_poses3D, projected_points2D
return joints2D, joints3D, optimized_poses3D, projection2D

0 comments on commit 12ce71f

Please sign in to comment.