Aly
Aly

Reputation: 16265

Calculate Camera space coordinates from vtk render

I have rendered an image in vtk, I would like to project the image points (x,y) to 3D camera frame coordinates. For each pixel (x,y) I have the z value in the camera frame (obtained from the z-buffer).

Under the pinhole projection, the standard way to do this would be:

x_camera_frame = (x_pixel - cx) * z_camera_frame/ fx;

y_camera_frame = (y_pixel - cy) * z_camera_frame / fy;

where fx and fy are the focal length and cx cy is the centre of projection of the camera (intrinsic parameters).

The problem is, with vtkCamera you can only set the field of view but there is not way to set or get the focal length or center of projection, so how would I go about calculating x_camera_frame and y_camera_frame?

Upvotes: 1

Views: 1929

Answers (1)

Arun R
Arun R

Reputation: 891

Normally the center of projection is the camera position ie. (0,0,0) in the camera space. That means the top left corner of your image should be at P = (-imagewidth/2, -imageheight/2, fl), (fl is the focal length) assuming no further 2d transforms (croping, resizing etc) are applied after the perspective transform.

P here represents the point in the image plane seen from the camera space. To convert it multiply by the inverse of the projection matrix and you should be able to get the point in camera space.

I assume you know what the image width and height are. To get the focal length, the distance between the camera and the focal point can be used. The API also returns the Projection Transform Matrix, so you can calculate its inverse, before applying it to the image plane point.

arun

Upvotes: 1

Related Questions