# Matching a virtual camera to a physical camera

Say I've got a photograph of a scene, and measurements for part of it (eg. a room where I know the dimensions of the walls). Assuming a rectilinear lens, how would I go about setting up a virtual camera so that 3D objects are rendered as if they were in the physical scene?

This is the Camera re-sectioning problem.

We need to have a few points, like the end points of the walls, to take the roles of xw, yw and zw in the following equation: Here A is defined as: These are the values of the camera itself.

R and T are defined as the Rotation and Translation matrices for the camera, and are the values we need to solve for. The position, C, of the camera expressed in world coordinates is C = -R-1T = -RT T .

The linked Wikipedia article mentions a few algorithms to solve these equations.

An example of a practical application of these is also found on Math Stack Exchange.

Another example, with some code samples that you may want to use, is found Stack Overflow.