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

Weak-perspective camera coordinates #1

Closed
vladsterz opened this issue May 9, 2019 · 7 comments
Closed

Weak-perspective camera coordinates #1

vladsterz opened this issue May 9, 2019 · 7 comments

Comments

@vladsterz
Copy link

Hello, great job.
I've a question about the estimated perspective camera position. I assume that the SMPL model goes as (x,y,z) and after watching the values at the estimated camera I noticed that the first coefficient was big ( x? ) , but I expected the last coordinate to be big ( z )

@nkolot
Copy link
Owner

nkolot commented May 9, 2019

If you look at how we are computing the orthographic projection:

def orthographic_projection(X, camera):
    """Perform orthographic projection of 3D points X using the camera parameters
    Args:
        X: size = [B, N, 3]
        camera: size = [B, 3]
    Returns:
        Projected 2D points -- size = [B, N, 2]
    """ 
    camera = camera.view(-1, 1, 3)
    X_trans = X[:, :, :2] + camera[:, :, 1:]
    shape = X_trans.shape
    X_2d = (camera[:, :, 0] * X_trans.view(shape[0], -1)).view(shape)
    return X_2d

You can see that the first coefficient in the camera is the scaling factor whereas the second and third the translation in the x and y direction. So more formally, the transformation we are doing is

[X,Y,Z] -> camera[0] * [X+camera[1], Y+camera[2]]

I hope this helps

@vladsterz
Copy link
Author

Thanks for the fast reply.
This in fact helps alot.

@vladsterz
Copy link
Author

vladsterz commented May 13, 2019

Hello, I can't figure how to use the predicted camera parameters in order to project the predicted points of the model onto the image.

Actually I want to make my intention clear. Given this camera parameters and the predicted SMPL model, is it possible for me to project every point of the mesh to the image? How is it done?
As I understand, this is handled by OpenDR.
Thanks in advance.

@vladsterz vladsterz reopened this May 13, 2019
@nkolot
Copy link
Owner

nkolot commented May 13, 2019

The orthographic projection function that I mentioned above projects the mesh in the normalized image plane. If you want to do the projection in pixel coordinates, you have to convert the projected coordinates from [-1,1] to [0,224] by a simple translation and scaling.

You can also do the perspective projection from scratch as K * [R,t] * [X,Y,Z] as we show in demo.py. Assuming a fixed focal length, first we get the camera translation

camera_translation = torch.stack([pred_camera[:,1], pred_camera[:,2], 2*FOCAL_LENGTH/(224 * pred_camera[:,0] +1e-9)],dim=-1)

This is t in the above projection equation. R will be the identity matrix and K will be

        FOCAL_LENGTH                0                  224/2
K =          0                 FOCAL_LENGTH.           224/2
             0                      0                    1

@vladsterz
Copy link
Author

Thanks once again for the helpful response. Closing it, for now...

@RohanChacko
Copy link

Hi,
Can you tell me how you arrived at the tz term in the translation expression
camera_translation = torch.stack([pred_camera[:,1], pred_camera[:,2], 2*FOCAL_LENGTH/(224 * pred_camera[:,0] +1e-9)],dim=-1)? It would be helpful if you could explain the reasoning.

@Ironbrotherstyle
Copy link

Same question. If you have any mathematical solution, please let me know, thank you.

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

4 participants