OpenGL ES Screen Projection Matrix and Camera Projection Matrix

Cameron Lowell Palmer

I have a projection matrix derived from the camera calibration in an augmented reality app and as long as the screen aspect ratio matches the camera image aspect ratio everything is fine. When the camera image doesn't match the screen edge-for-edge you'll get distortion in the tracking.

The problem scenarios:

  • 1280x720 video on an iPad
  • 640x480 video on an iPhone 5S.

The working scenarios:

  • 640x480 video on an iPad
  • 1280x720 video on an iPhone 5S.

Goal: I want to handle this screen / camera aspect ratio mismatch in a general way.

Example of letterbox format

This problem exists because the view has normalized device coordinates in the aspect ratio of the screen (4:3 for iPad), whereas the projection matrix has an aspect ratio of the camera image (16:9 for 720p). The background image needs to match up to the projection matrix or the illusion of augmented reality fails so if I want to toggle between 'fit' and 'fill' I'll need to change projection matrix to match the image size.

Note: I'm looking to deal with this problem without an OpenGL specific solution. So I'm looking for a more general mathematical answer that involves manipulating the projection matrix.

solidpixel

However, I realize I need to map the camera's projection matrix to the screen projection matrix or perhaps scale it.

Aspect ratio really just determines what is on screen (i.e. amount of peripheral vision you get) - it shouldn't fundamentally change the projection (assuming you keep the near and far clips the same).

First thing to note is that there isn't really a safe mapping (i.e. not every coordinate in the screen view has an equivalent in the camera view, and visa-versa).

To avoid distortion you really have two options - clip to the narrower of the two options (discard information) or scale down with letter box and keep the original aspect ratio (discard screen-area) .

Both feel like it should be possible with a simple scale factor applied to the final clip-space transform (assuming you clip equally on both sides of the frustum you should just be able to multiply up the clip-space coordinate of the axis you want to clip (scale > 1), or multiple down (scale < 1) if you want letterbox). To make letterboxing work you'll need to to use glViewport or glScissor to stop primitives outside of the letterbox being drawn.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Orthographic Camera Projection matrix

From Dev

Camera calibration: the projection matrix

From Dev

Is the projection matrix in OpenGL really a "projection matrix"?

From Dev

OpenGL Projection/Matrix confusion

From Dev

Outside of projection matrix? (OpenGL)

From Dev

Pinhole camera projection matrix explained

From Dev

Wikitude camera projection Matrix Unity

From Dev

Intrinsic Camera Matrix to OpenGL Projection. Unexpected Scaling Factor

From Dev

perspection projection matrix not working openGL

From Dev

Camera projection matrix: why transpose rotation matrix?

From Java

Opengl es on android problem with object opsition on projection matrix

From Dev

OpenGL ES 2.0: What is the link between projection matrix and aspect ratio?

From Dev

how to get camera projection matrix using the matlab?

From Dev

how to get camera projection matrix using the matlab?

From Dev

OpenGL projection matrix for perspective with fovy and aspect

From Dev

Perspective Projection Matrix in OpenGL appears black

From Dev

Proper calculation for the first element of an OpenGL projection Matrix?

From Dev

OpenGL projection matrix for perspective with fovy and aspect

From Dev

List of rotation matrix for object projection on screen in android

From Dev

Similarity transformation of projection matrix

From Dev

Projection matrix implementation

From Dev

Projection of rotation matrix

From Dev

QOpenGLWidget overriding projection matrix

From Dev

How do I get the projection matrix of a camera after stereo rectification?

From Dev

glLookAt moves camera position when lookAt is moved - role of projection matrix?

From Dev

Camera projection of mesh using opengl

From Dev

Why does this projection matrix not work?

From Dev

How does a projection Matrix work?

From Dev

Last Row of the perspective projection matrix

Related Related

  1. 1

    Orthographic Camera Projection matrix

  2. 2

    Camera calibration: the projection matrix

  3. 3

    Is the projection matrix in OpenGL really a "projection matrix"?

  4. 4

    OpenGL Projection/Matrix confusion

  5. 5

    Outside of projection matrix? (OpenGL)

  6. 6

    Pinhole camera projection matrix explained

  7. 7

    Wikitude camera projection Matrix Unity

  8. 8

    Intrinsic Camera Matrix to OpenGL Projection. Unexpected Scaling Factor

  9. 9

    perspection projection matrix not working openGL

  10. 10

    Camera projection matrix: why transpose rotation matrix?

  11. 11

    Opengl es on android problem with object opsition on projection matrix

  12. 12

    OpenGL ES 2.0: What is the link between projection matrix and aspect ratio?

  13. 13

    how to get camera projection matrix using the matlab?

  14. 14

    how to get camera projection matrix using the matlab?

  15. 15

    OpenGL projection matrix for perspective with fovy and aspect

  16. 16

    Perspective Projection Matrix in OpenGL appears black

  17. 17

    Proper calculation for the first element of an OpenGL projection Matrix?

  18. 18

    OpenGL projection matrix for perspective with fovy and aspect

  19. 19

    List of rotation matrix for object projection on screen in android

  20. 20

    Similarity transformation of projection matrix

  21. 21

    Projection matrix implementation

  22. 22

    Projection of rotation matrix

  23. 23

    QOpenGLWidget overriding projection matrix

  24. 24

    How do I get the projection matrix of a camera after stereo rectification?

  25. 25

    glLookAt moves camera position when lookAt is moved - role of projection matrix?

  26. 26

    Camera projection of mesh using opengl

  27. 27

    Why does this projection matrix not work?

  28. 28

    How does a projection Matrix work?

  29. 29

    Last Row of the perspective projection matrix

HotTag

Archive