Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with projection Matrix #56

Open
josephbiko opened this issue Dec 22, 2021 · 0 comments
Open

Help with projection Matrix #56

josephbiko opened this issue Dec 22, 2021 · 0 comments

Comments

@josephbiko
Copy link

josephbiko commented Dec 22, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant