Skip to content

Help with projection Matrix #56

@josephbiko

Description

@josephbiko

I am trying to calculate the pixel coordinates of the landmarks.
(Parameters are copied from the render helper).

def viewport(x, y, w, h):
    x, y, w, h = map(float, (x, y, w, h))
    return np.matrix([[w/2, 0  , 0,x+w/2],
                      [0  , h/2, 0,y+h/2],
                      [0  , 0  , 0.5,  0.5],
                      [0  , 0  , 0,    1]])

size = 800

frustum_ = {'near': 0.01, 'far': 3.0, 'height': 800, 'width': 800}
camera_params = {'c': np.array([400, 400]),
                 'k': np.array([-0.19816071, 0.92822711, 0, 0, 0]),
                 'f': np.array([4754.97941935 / 2, 4754.97941935 / 2])}

landmarks = mesh_points_by_barycentric_coordinates(m.v,m.f,flame_embedding['lmk_face_idx'],flame_embedding['lmk_b_coords'])
 


pose_mat = [[1, 0, 0, 0],
            [0, 1, 0, 0],
            [0, 0, 1, 1],
            [0, 0, 0, 1]]

camera = pyrender.IntrinsicsCamera(fx=camera_params['f'][0],
                                  fy=camera_params['f'][1],
                                  cx=camera_params['c'][0],
                                  cy=camera_params['c'][1],
                                  znear=frustum_['near'],
                                  zfar=frustum_['far'])

P = camera.get_projection_matrix(size,size)
V = np.linalg.inv(pose_mat)
M = np.eye(4)
Vw= viewport(0,0,size,size)

landmarks_expanded = np.ones((68,4)) 
landmarks_expanded[:68,:3] = landmarks

expanded = (Vw@P@V@landmarks_expanded.T).T
plt.scatter([expanded[:,0]],[expanded[:,1]])
plt.show()
plt.scatter([landmarks[:,0]],[landmarks[:,1]])
plt.show()

`
But the resulting image is a bit skewed.
I'm probably doing something wrong... but not sure what.
Any help would be greatly appreciated!

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions