Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create perspective projection matrix, given focal points and camera principal center

Tags:

I managed to acquire camera's intrinsic and extrinsic parameters using OpenCV, thus I have fx, fy, cx and cy. And I also have the screen / image's width and height.

But how do I create an OpenGL perspective projection matrix from these parameters?

glFrustrum shows how to create projection matrix, given Z near, Z far and the image width and height. But how do I include focal points and camera centers in this matrix?

enter image description here

like image 826
sub_o Avatar asked Feb 27 '14 09:02

sub_o


People also ask

How do you calculate perspective projection?

This how or when more precisely the perspective divide is performed when a point is multiplied by a projection matrix. It is important you understand this idea. Then divide all coordinates by w' to set the point's homogeneous coordinates back to Cartesian coordinates: x′=x′=xw′=−z,y′=y′=yw′=−z,z′=z′=−zw′=−z=1.

What is the projection matrix of a camera?

In computer vision a camera matrix or (camera) projection matrix is a. matrix which describes the mapping of a pinhole camera from 3D points in the world to 2D points in an image.


2 Answers

You can check the following links

Kyle Simek's explanation

My explanation

like image 115
koshy george Avatar answered Sep 24 '22 10:09

koshy george


Here is the code to obtain the OpenGL projection matrix equivalent to a computer vision camera with camera matrix K=[fx, s, cx; 0, fy, cy; 0, 0, 1] and image size [W, H]:

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity();            // Reset The Projection Matrix
GLdouble perspMatrix[16]={2*fx/W,0,0,0,2*s/W,2*fy/H,0,0,2*(cx/W)-1,2*(cy/H)-1,(zmax+zmin)/(zmax-zmin),1,0,0,2*zmax*zmin/(zmin-zmax),0};
glMultMatrixd(perspMatrix);

NB: zmin and zmax represent the near and far Z clipping planes. This formulation assumes that the OpenGL world coordinate frame is chosen as follows:

enter image description here

The OpenGL camera is assumed to be located at the origin, looking towards positive Z axis, with a down vector collinear and towards the positive Y axis.

like image 42
BConic Avatar answered Sep 26 '22 10:09

BConic