geopavlakos / hamer

HaMeR: Reconstructing Hands in 3D with Transformers
https://geopavlakos.github.io/hamer/
MIT License
400 stars 39 forks source link

How to get the 3D coordinates of the camera coordinate system of each vertices #59

Closed hahamini closed 2 months ago

hahamini commented 2 months ago

I want to get the 3D coordinates of the camera coordinate system of each vertices. In #30, it said to add pred_cam_t_full to vertices or keypoints, so I did that. Then, for verification, I projected it to a 2D plane, but I think it's wrong, so I'm posting a question.

...
pred_cam_t_full
vertices = out["pred_vertices"][0].detach().cpu().numpy()
cam_mat = np.array([[camera_matrix['fx'], 0, camera_matrix['cx']],
                    [0, camera_matrix['fy'], camera_matrix['cy']],
                    [0, 0, 1]])

def project_to_2d(vertices, K):
    vertices_2d = []
    for vertex in vertices:
        projected = K @ (vertex + pred_cam_t_full).T
        projected = projected / projected[-1]
        vertices_2d.append(projected[:2])
    return np.array(vertices_2d)

vertices_2d = project_to_2d(vertices, cam_mat)
geopavlakos commented 2 months ago

What values are you using for the camera matrix? The translation pred_cam_t_full is computed here using specific intrinsics (focal length is the scaled_focal_length value and the center of projection is at the center of the image). You will need to use these values when you do the projection.