Shaondip Bhattacharya
Shaondip Bhattacharya

Reputation: 51

3D world coordinate to 2D image coordinate conversion

If the camera coordinates in the world frame (x1, y1, z1) are available along with the camera attitude quaternions (or pitch roll and yaw) then how do I map a pixel (x,y) onto the camera image - given the coordinates of the pixel object (x2,y2,z2) in the world frame? I am a complete newbie into computer vision. Even a link to a relevant tutorial will be much appreciated.

Upvotes: 0

Views: 1224

Answers (1)

clabe45
clabe45

Reputation: 2454

1. Create the view (camera) matrix

Pseudocode:

view = new Matrix4();
view.rotate(camRotationQuaternion);
view.translate(camX, camY, camZ);

2. Multiply the vertex by the view matrix

Pseudocode:

vertexCam = view * vertexWorld;

3. Get the x and y values of the transformed point (in camera space)

Since the point is now being "seen" from the view matrix, its z value represents the depth from the camera, and its x and y values represent the pixel coordinate on the flat "image" of the camera.

Pseudocode:

pixX = vertexCam.x;
pixY = vertexCam.y;

Upvotes: 0

Related Questions